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

Pete Prodoehl pete.prodoehl at cygnusinteractive.com
Mon May 14 13:36:22 CDT 2001


Oops!


_____________________________________

#!perlmy $filein = ':20';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"; };

_____________________________________


> ----------
> From: 	Pete Prodoehl
> Reply To: 	thelist at lists.evolt.org
> Sent: 	Monday, May 14, 2001 1:35 PM
> To: 	'thelist at lists.evolt.org'
> Subject: 	RE: [thelist] perl: show me the last n lines from this file
> 
> 
> 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
> 
> 
> 
> 
> ---------------------------------------
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt ! 
> 
> 
_____________________________________________________
For more information about Cygnus Business Media, please visit our 
Web site at www.cygnusb2b.com







More information about the thelist mailing list