grep returns the elements of a list for which expression is true. In this case, your list is the array ($line), and your expression is the /$pat/gi. Therefore, @apples will simply be set to ($line) if the pattern /$pat/gi matches, otherwise will be set to nothing.
Because each of your lines of data has at least one 'apple' in them, the grep count will simply equal the number of lines.
- Miller
In reply to Re: m// vs grep for counting occurances of a string
by wind
in thread m// vs grep for counting occurances of a string
by Plankton
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |