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.
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.# open the file using _ to avoid multiple system calls invoked by perl open _,"filename";
This will crash with memory exhaustion if the file is too largemy @lines=<_>;
With warnings enabled, that will give:@lines[$#lines];
But could be even better written asScalar value @lines[$#lines] better written as $lines[$#lines]
$lines[-1]
Dave.
|
---|
In Section
Seekers of Perl Wisdom