Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: map {} list or do {} for list?

by SuicideJunkie (Vicar)
on Apr 11, 2014 at 14:30 UTC ( #1081976=note: print w/replies, xml ) Need Help??

in reply to map {} list or do {} for list?

map returns a list. It should be used when you want the list being generated as output.

do{...} for should be used when you just want to do things in a loop.

Since you have your statement in void context, you obviously don't want any output. Thus, the for loop is what you want.

Replies are listed 'Best First'.
Re^2: map {} list or do {} for list?
by Random_Walk (Prior) on Apr 11, 2014 at 15:27 UTC

    That was my feeling about map too. But I have seen it used void in a few bits of code recently, and wondered if there was any solid argument for or against, other than it looks wrong :)


    Pereant, qui ante nos nostra dixerunt!

      Well, it certainly still works, but its misleading. You're building a big list of results and then immediately throwing it away.

        Wasn't that optimized not to happen in void context?
        لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1081976]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2020-11-28 11:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found