On Sat, Jan 11, 2003 at 02:00:58PM -0800, John W. Krahn wrote:
> Rob Dixon wrote:
> > "Michael Kelly" <[EMAIL PROTECTED]> wrote
> > > # print out all the captured numbers
> > > map{ print "$_\n"; } @numbers;
> > 
> > Hi Michael.
> > 
> > May I warn against using 'map' in a void context like this? It'll work,
> > sure, but you're using it for the side-effect of evaluating the 'print'
> > expression. map's purpose is to 'translate' one list into another, and here
> > it is faithfully producing a list of (presumably) 'true' values to indicate
> > print's success in outputting each array element. This list occupies memory,
> > may be huge, and just gets discarded. Better to use 'foreach' like this:
> > 
> >    print "$_\n" foreach @numbers;
> 
> Or just print the list that map produces.
> 
> print map { "$_\n" } @numbers;

Thanks, Rob and John. Somehow the "map in void context" discussions that
have come up here at various times never got through to me. I should
remember this time...

-- 
Michael
[EMAIL PROTECTED]
http://www.jedimike.net/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to