Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: how can i read only the last line of a files

by perladdict (Chaplain)
on Aug 03, 2006 at 10:03 UTC ( #565416=note: print w/replies, xml ) Need Help??


in reply to how can i read only the last line of a files

hi monk,
i saw your code,u are reading the content of files in an array.below subroutine may helps to read the last content of arrays.
@last=lastlines(\@a,\@b,\@c); print "@last\n"; sub lastlines { my @retlist=(); foreach my $aref(@_) { push @retlist,pop @$aref; } return @retlist; }
.

Replies are listed 'Best First'.
Re^2: how can i read only the last line of a files
by davidrw (Prior) on Aug 03, 2006 at 11:57 UTC
    This is equivalent code (though note davorg's reply for a much more robust solution) ... no need to iterate through everything:
    sub lastlines { return map { $_[-1] } @_; } # or, w/o using a sub: @last = ($a[-1], $b[-1], $c[-1]);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://565416]
help
Chatterbox?
[thezip]: oops... My mind is backwards (this works): find . -mindepth 2 -name "*.csv" | xargs wc -l

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2016-12-06 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (113 votes). Check out past polls.