[thelist] perl: show me the last n lines from this file

Pete Prodoehl pete.prodoehl at cygnusinteractive.com
Mon May 14 13:32:27 CDT 2001


Here's mine:

I build an array that has 20 items in it, as soon as it has more than 20, it
starts dropping them from the front of the list...

You can change how many it holds with the $howmany variable...

______________________________________________
#!perlmy $filein = '/path/to/your/file';my $howmany = 20;my @arr;my $ct =
1;open (FILEIN, "<$filein") or die ("Oops! Could not open $filein:
$!");while (defined ($line = <FILEIN>)) {	chomp $line;		push
(@arr, $line);	if ($ct > $howmany) {		shift (@arr);	}
$ct++;}close (FILEIN);foreach $item (@arr) { print "$item\n"; };
______________________________________________


> ----------
> Subject: 	Re: [thelist] perl: show me the last n lines from this file
> 
> Sam-I-Am wrote:
> > 
> > I'm trying to build a page (cgi) that displays the last say 20 access
> > from the web access-log. (or 5k, or whatever)
> 
> Starting with your code snippet, I tried this:
> --------------------------------------------------------------------
> 
_____________________________________________________
For more information about Cygnus Business Media, please visit our 
Web site at www.cygnusb2b.com







More information about the thelist mailing list