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

Re^2: Spot the bug

by Perl Mouse (Chaplain)
on Dec 21, 2005 at 10:46 UTC ( [id://518278]=note: print w/replies, xml ) Need Help??


in reply to Re: Spot the bug
in thread Spot the bug

And for small hashes, that is fine. It's less so for a general purpose function in a module - it might get passed in a large hash, possibly even one that's tied to storage on disk.
Perl --((8:>*

Replies are listed 'Best First'.
Re^3: Spot the bug
by demerphq (Chancellor) on Dec 21, 2005 at 14:32 UTC

    The problem is people have a bad habit of forgetting to reset the iterator, and heaven help you if the general routine calls back out to uncontrolled code from inside the loop. Can you say "infinite loop"? :-)

    ---
    $world=~s/war/peace/g

      The problem is people have a bad habit of forgetting to reset the iterator,
      Yes, and? As long as you don't forget it in your general routine (unless you have good reason not to).
      heaven help you if the general routine calls back out to uncontrolled code from inside the loop.
      Yes, and? Presumably the uncontrolled code was passing in as an argument, one way or the other (otherwise, it wouldn't be uncontrolled). It's the users responsibility, just as it's the users responsibility to not pass in vital files as arguments to unlink.

      Iterators hand the programmer some rope, but what doesn't? That's not a reason to avoid iterators all together.

      Perl --((8:>*

        I think the problem is not with iterators as such, as much as with the fact that the scope and workings of this particular iterator are so non-obvious. In other words, it's the "magic" the bites here, IMO, not the iterator. I posted a hash iterator class some months ago that lets one create multiple simultaneous lexically-scoped iterators on any hash, but somehow it feels like overkill for most situations. Maybe this is a facility that should be built-in.

        the lowliest monk

Re^3: Spot the bug
by merlyn (Sage) on Dec 21, 2005 at 17:04 UTC
    Well, I'd argue that any program for which the difference between a keys-based walk and an each-based walk is significant shouldn't be using hashes that large, not with the arrival of things like DBD::SQLite or other cheap databases.

    Yes, it mattered when Perl was running on 10Mhz 1Megabyte machines, and databases were tough, so a DBM hash was a cool thing. Those are long gone. {grin}

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Oh sure. But you don't always live in an ideal world. Sometimes, the data format is given, and Perl (and the programmer) just has to adapt. That's what Perl is supposed to be good at.
      Perl --((8:>*

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2025-06-19 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.