Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Forcing array context on a file handle

by BrowserUk (Pope)
on Oct 30, 2012 at 21:05 UTC ( #1001553=note: print w/ replies, xml ) Need Help??


in reply to Forcing array context on a file handle

If there's any chance that the file can be of any real size at all, and you only want the line count, you'd be much better off using:

my $lines; ++$lines while <$file>;

Building a potentially huge list only to throw it away, just to count the lines, will be very costly in terms of time and memory.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong


Comment on Re: Forcing array context on a file handle
Download Code
Re^2: Forcing array context on a file handle
by choroba (Abbot) on Oct 31, 2012 at 01:31 UTC
    Or even
    1 while <$file>; print $.;
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Indeed. But that's idiomatic, so lisp programmers probably won't understand it and PerlCritic would probably have an apoplectic hissy fit.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      RIP Neil Armstrong

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001553]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-12-28 12:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (181 votes), past polls