Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Reading Text Lines

by smokemachine (Hermit)
on May 11, 2006 at 19:18 UTC ( [id://548806]=note: print w/replies, xml ) Need Help??


in reply to Reading Text Lines

could be this?
perl -ne '$pages[$i].=$_;$i++unless$.%100' file

Replies are listed 'Best First'.
Re^2: Reading Text Lines
by ikegami (Patriarch) on May 11, 2006 at 19:22 UTC

    Why keep 100MB in memory when you only need a few KB at a time?

    Why read the entire file when only displaying the first page?

    By the way,
    if$.%100==0
    is shorter and clearer than
    unless$.%100

      if$.%100==0 is shorter and clearer than unless$.%100

      I believe it's a matter of taste. My (maybe weird) way of thinking is that I'm interested in $a % $b when the modulo operator yields a false value, in the same way that I'm interested in $a == $b when the result is true. So, the alternatives are:

      if $a % $b == 0 if !($a % $b) if not $a % $b unless $a % $b

      To me, the clearest of them is the last one. Maybe it's because I use it regularly. Note that the one you said was shorter and clearer is the longest of that four, once we beautify the code.

      --
      David Serrano

        Negation where it is not needed, the treatment of a numerical formula as boolean and especially their conjunction may not be confusing to you, but it is confusing to many with whom I've worked.

        "once we beautify" doesn't count when golfing. That's what the poster of the parent to my reply appeared to have been doing.

        "unless $a % %b" is also clearer to me, but it is not clearer to my colleques, nor to others (according to "Perl Best Practices"). I've found I've had to give up a number of my math-major tendencies so that my collegues can clearly see what's going on in the code I write. It's not always easy to do that.
      Sorry... 100mb? i didn't read this...
      :wq

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 14:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found