in reply to playing with map
map basically says "take this list, do something to every element in it, and give me the resulting list."
grep basically says "take this list, find all elements for which this expression is true, and give me the resulting list."
in general you don't want to use either of these functions in a void context, i.e. you wouldn't run them without assigning the list they return to some variable. also, you wouldn't want to use them unless you want to iterate through the entire list. in either of these situations, a foreach loop (with a call to last in the second situation) is more appropriate.
your realization and reconstruction of the map usage to assign the results of the operation to @n was correct. you couldn't do it with a grep call, because grep returns some subset of the original list. it doesn't make any modifications. also, as you said, why would you want to?
Update:Whoops.. guess i should have re-read the grep info before i made that last statement (=
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: playing with map
by snowcrash (Friar) on Mar 09, 2001 at 13:45 UTC | |
|
Re: Re: playing with map
by jeroenes (Priest) on Mar 09, 2001 at 13:51 UTC | |
by tye (Sage) on Mar 09, 2001 at 21:07 UTC | |
by greenFox (Vicar) on Mar 10, 2001 at 15:37 UTC | |
by tye (Sage) on Mar 11, 2001 at 00:09 UTC | |
by mkmcconn (Chaplain) on Mar 10, 2001 at 16:26 UTC | |
by merlyn (Sage) on Mar 10, 2001 at 16:29 UTC | |
by tilly (Archbishop) on Mar 09, 2001 at 21:20 UTC | |
by merlyn (Sage) on Mar 09, 2001 at 21:43 UTC |