Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by SuicideJunkie (Vicar)
on Apr 11, 2014 at 16:06 UTC ( [id://1081996]=note: print w/replies, xml ) Need Help??


in reply to Re^2: map {} list or do {} for list?
in thread map {} list or do {} for list?

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

Replies are listed 'Best First'.
Re^4: map {} list or do {} for list?
by choroba (Cardinal) on Apr 11, 2014 at 16:08 UTC
    Wasn't that optimized not to happen in void context?
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      It's a FAQ of its own. Per perl581delta: "map in void context is no longer expensive. map is now context aware, and will not construct a list if called in void context".

      Sorry, I didn't mean to imply that it wasn't optimized away.

      I meant that when reading the code, map says "Hey! Pay attention to the return values of this code block, we're making a list of them."

        Well, the same could be said of "$i++;'. In other words, if god had not meant us to throw away results, he wouldn't have given us void context ;-)

      It looks like it is well optimised. See my benchmarks, currently at the end of the thread.

      Cheers,
      R.

      Pereant, qui ante nos nostra dixerunt!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-19 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found