Gossamer Forum
Home : General : Perl Programming :

limit file number

Quote Reply
limit file number

I was wanting to know how to go about limiting the number of files returned (print command) by a script.

The script I have returns all the new items (auction items) within a 24 hour period.

The trouble is that it lists ALL the items, I'd like it to display just the last 15 new items.

Is this possible?

Quote Reply
Re: [ceo] limit file number In reply to
Hey Paul,

Can you show us what code you have now to return all the items? You're asking a pretty generic question. If you can narrow it down a bit, you'll have a better chance at getting an answer.

Quote Reply
Re: [Chaz] limit file number In reply to
Here's the code I'm using now:


require "cat.cgi";
$basepath = '/.../.../..../';
$scripturl = ".....";
%category = (%categoryantiques, %categoryautomotive, %categorybooks, %categorycloth, %categorycollect, %categorycomphard, %categorycompsoft, %categoryelec, %categoryentain, %categoryhouse, %categoryintell, %categoryjewel, %categorypet, %categorypot, %categorysport, %categorytool, %categorytoy, %categorytravel);
$gmoff = 3600;
$newdays = 30;
print "Content-type: text/html\n\n";
foreach $key (sort keys %category) {
opendir THEDIR, "$basepath$key" || die "Unable to open directory: $!";
@allfiles = readdir THEDIR;
closedir THEDIR;
foreach $file (sort { int($a) <=> int($b) } @allfiles) {
if (-T "$basepath$key/$file") {
open THEFILE, "$basepath$key/$file";
($title, $reserve, $inc, $desc, $image, $feat, $quantity, $shipping, $payment1, $payment2, $payment3, $payment4, $payment5, $payment6, $payment7, $payment8, $payment9, $place, $countryid, $ship, $currency, $grabber, $condition, $counter, $bold, $img, $buyit, $highlite, @bids) = <THEFILE>;
close THEFILE;
chomp($title, $reserve, $inc, $desc, $image, $feat, $quantity, $shipping, $payment1, $payment2, $payment3, $payment4, $payment5, $payment6, $payment7, $payment8, $payment9, $place, $countryid, $ship, $currency, $grabber, $condition, $counter, $bold, $img, $buyit, $highlite, @bids);
@lastbid = split(/\[\]/,$bids[$#bids]);
@firstbid = split(/\[\]/,$bids[0]);
$file =~ s/\.dat//;
@closetime = localtime($file - $gmoff);
$timediff = ($file - time);
$name = $title;
$name = substr $name, 0, 50;
$name .= '...';
if (time < ($newdays * 86400 + $firstbid[3])) {
print "<table cellpadding=0 cellspacing=0 border=0><tr><td valign=baseline><A HREF=$scripturl\?$key\&$file><font face=\"geneva, verdana, arial\" size=\"1\" color=black><b>$name</b></font></A>&nbsp;<font face=\"geneva, verdana, arial\" size=\"1\" color=black><br>currently \$$lastbid[2]</font></td></tr></table>" if ($timediff > 0);