BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:

Never mind: -nl autochomps!

When I run this:

S:\>perl.exe -nle"1+index($_, 'clanks') and print" 8gb.txt | wc -l 2048

It reports 2048 hits, which is the same as grep finds:

S:\>grep -F clanks 8gb.txt | wc -l 2048

But when I run this:

S:\>perl -le"while(<>){ 1+index($_, 'clanks') and print; }" 8gb.txt | +wc -l 4096

The number of hits doubles. Can you see why?


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.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Replies are listed 'Best First'.
Re: IO mystery (Solved!)
by afoken (Chancellor) on Jun 28, 2015 at 18:51 UTC

    Did you just look at the line counts or did you look at the actual output of the two variants?

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      With the file containing 4096 byte lines of random characters, watching them spew up the screen didn't tell me anything useful.


      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.
      I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

        I would have used diff on the two outputs.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)