in reply to Re: peeling the top 10 lines from a file
in thread peeling the top 10 lines from a file
The problem with his while( (<>) && $counter < 10 ) {... (besides the fact that he's missing a sigil) is apparent when you turn on warnings and look at the output. Once you add the logical short circuit, the magic while(<>) is lost, and you end up with a plain old boolean evaluation of the <> operator. That results in two problems.
First, $_ doesn't receive the current line of the file without explicitly assigning it. Try it with warnings and you'll see "Uninitialized value....." warnings for each line. Second, as the warnings also state, "Value of handle construct can be "0", test with defined()."
Dave
|
|---|