in reply to m// vs grep for counting occurances of a string

Read the grep documentation. grep returns a single item ($line) regardless of the number of matches found in the regex so @apples will contain either no elements, or a single element containing $line.

The regex on the other hand returns an element for each match so you get two elements in @apples for the first line where there are two matches.


DWIM is Perl's answer to Gödel
  • Comment on Re: m// vs grep for counting occurances of a string

Replies are listed 'Best First'.
Re^2: m// vs grep for counting occurances of a string
by Plankton (Vicar) on Aug 11, 2007 at 02:05 UTC
    Thank you monks! You just saved me from making a embarrassing bug.