in reply to Grep Fuunction

They are both filters working on a list. For each element of the list, the first argument of grep or map is executed (this argument being either an expression or a block). Just before the execution, $_ is set the element being processed.

grep and map differ in the return values. The former will always returns a subset of the original list (the entire list is a subset as well). An element of the original list will be returned if the expression (or block) returned a true value when that element was processed. The return value of map is a list consisting of the actual return values of the expression or block.

Abigail

Replies are listed 'Best First'.
Re: Re: Grep Fuunction
by smitz (Chaplain) on Jun 12, 2002 at 10:13 UTC
    I swear on life, I have read every perldoc and Monastery Example on map (and sometimes grep). Pages and pages of intructions, and just have since avoided using it.
    But now I get it!
    One little paragraph, thank you so much! Maybe you should re-write all the perldocs ;-)

    SMiTZ