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

Re^2: Printing Last Element of a line using perl memory?

by dave_the_m (Prior)
on Feb 15, 2013 at 12:53 UTC ( #1018887=note: print w/replies, xml ) Need Help??


in reply to Re: Printing Last Element of a line using perl memory?
in thread Printing Last Element of a line using perl memory?

That code is bad in so many ways.
# open the file using _ to avoid multiple system calls invoked by perl open _,"filename";
This is complete nonsense. Using an underscore as the filename makes no difference to the execution, but makes the code harder to understand. Also, you should normally use lexical filehandles. Lastly, there's no error checking on the open.

my @lines=<_>;
This will crash with memory exhaustion if the file is too large
@lines[$#lines];
With warnings enabled, that will give:
Scalar value @lines[$#lines] better written as $lines[$#lines]
But could be even better written as
$lines[-1]

Dave.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018887]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2016-12-05 16:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (89 votes). Check out past polls.