Re: Perl Question
from "man perlfunc"
grep BLOCK LIST
This is similar in spirit to, but not the same as, grep(1) and
its relatives. In particular, it is not limited to using regular
expressions.
Evaluates the BLOCK or EXPR for each element of LIST (locally
setting $_ to each element) and returns the list value consisting of those
elements for which the expression evaluated to true.
I assume that "grep $doc, <at> list" is equivalent to "grep {$doc} <at> list", and your
$doc values were clearly true. The BLOCK version of grep is very useful to
apply more complex "examinations" than standard perl patterns.
On Thursday 31 July 2003 18:02, Danny Cox wrote:
> I was bitten by this yesterday (sorry, I was busy doing other things
> last night, or I would have posted then).
>
> I attempted to use the "grep EXPR, <at> list" described in "Programming
> Perl" and it didn't work as I expected.
>
> Background: I wanted to set up a list and stuff 3 digit numbers into it
> (actually EDI document names: 810, 850, 208, etc.). I wanted to use
> grep (the Perl grep) to let me know if that number was already extant.
> So, I used the following fragment:
>
> $count = grep $doc, <at> list
>
> where $doc == "810" for example. When the list was empty, $count was
(Continue reading)