Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Perl: the Markov chain saw
 
PerlMonks  

Re: Re^3: map-like hash iterator

by jdporter (Canon)
on Nov 06, 2002 at 21:32 UTC ( #210918=note: print w/ replies, xml ) Need Help??


in reply to Re^3: map-like hash iterator
in thread map-like hash iterator

Of course, if you're not in void context and actually intent on returning the resulting list from processing a 10,000,000 key hash, you'll have to be able to fit that in memory anyway.
Not necessarily always the case, though. The callback routine might never return anything -- except one time when it returns one thing. A jillion-key hash in, a one-element list out.

Just like map.


UPDATE

You can't have your cake and eat it - you can't be using an iterator when you're concerned about memory usage.
That is patently false. In fact, the built-in hash iterator (each) is all about efficiency -- in both space and time.

There is no reason why iterators can't be efficient.


Comment on Re: Re^3: map-like hash iterator
Select or Download Code
Re^5: map-like hash iterator
by Aristotle (Chancellor) on Nov 06, 2002 at 23:19 UTC

    That would be grep ;-) Still, that can be pretty wasteful. Why iterate over the entire 10,000,000 records even when the single one of interest is found at the very beginning? The iterators do not offer any early bailing mechanism.

    You have to look at the larger picture.

    Iterators mainly offer convenience. There are very few situations where iterators are useful under big efficiency concerns (be it memory or time), in the absence of lazy lists. Even so, you can't go wrong with the explicit loop construct.

    This ain't Ruby. :-) Perl 6 will, however, have lazy lists. (Is there anything Perl 6 won't fix? :-))

    Makeshifts last the longest.

      Why iterate over the entire 10,000,000 records even when the single one of interest is found at the very beginning? The iterators do not offer any early bailing mechanism.
      False. die works just fine.
      Iterators mainly offer convenience.
      And this is Perl. Sounds like a perfect match.

      Anyway, if you want to argue about it, let's meet in the chatterbox some time. Thank you for your comments.

        die works just fine.
        But how do you return the result then? Anyway.. :)

        Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (14)
As of 2014-04-18 19:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls