Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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?
[karlgoethebier]: choroba Nothing unclever in my sig. And remember: Beeing too clever is a bad mistake ;-)
[1nickt]: This is not to suggest that Karl should remove his slogan. Just thoughts of mine... Trust me I believe I am very much more radical than most, and if I had a slogan for every gross injustice in my sig, there would be no more bytes!
Discipulus redskins .. well native american..
[1nickt]: So if I was to offer any editorial advice it would be to (1) make it endure time passing (2) make it positive (3) make it about you and your beliefs
[1nickt]: (Disicpulus The new best choice is maybe "First People"
[karlgoethebier]: Discipulus: This is called "Volksverhetzung" in German which means
[karlgoethebier]: incitement of the people and it is prohibited by law
[1nickt]: The best sign I have sign in a protest march was carried by a kid of about 10 years "If you build a wall my generation will tear it down."
[1nickt]: ... sign I have seen ...
[1nickt]: Now that one made me hopeful! First time not angry in a long time when I saw that kid.

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2017-06-22 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (519 votes). Check out past polls.