![]() |
|
Perl-Sensitive Sunglasses | |
PerlMonks |
Re: do not understand grep exampleby moritz (Cardinal) |
on Jun 15, 2012 at 17:29 UTC ( #976466=note: print w/replies, xml ) | Need Help?? |
thought maybe it calls the subroutine with the entire list (even though this is not how grep is supposed to work), No, it does not. It calls the subroutine for every value in the list, and only returns if the subroutine returns a true value. So you could also write
As
and it would return the same result. That's what grep does: it goes through the list, calls the function for every value, and collect those values for which the function returned something true.
In Section
Seekers of Perl Wisdom
|
|