[ back to toc ]

Simple CGI Question

Date: 2002/02/25 14:00

Q:
This should be a real easy one for you, but I can't quite figure it out.

The following script accesses a .dat file that has a list of links in html
form. My question is how can I make this script output just the first
five or so links instead of outputting the entire thing? I've been told
it's really easy, but I haven't been able to figure it out.

Thanks again,

*NAME-DELETED*

Here is the script:

#!/usr/bin/perl

use CGI;
$query = new CGI;

print $query->header;

open(INF,"patsarticles.dat");
@articles = <INF>;
close(INF);

@articlelist = reverse (@articles);

foreach $line (@articlelist) {
chomp($line);
print "$line\n";

}

A:
$i = 0;
foreach $line (@articlelist)

chomp($line);
print "$line\n";
$i++;
last if $i >= 5;
}

Regards,
Peter

[ back to toc ]