Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^7: Spot the bug

by demerphq (Chancellor)
on Dec 22, 2005 at 09:12 UTC ( #518502=note: print w/replies, xml ) Need Help??


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

I dont think its fair to equate each(%hash) and filehandles, the reason being that I can have multiple filehandles open on the same file without any interference problems. But with each, you have to always consider that any traversal of the hash has to be completely independent. Thus a routine that takes a filename and traverses the file calling out a callback to process each chunk is totally safe. The equivelent routine that takes a hash and traverses it using each calling out to a callback runs the serious risk that the hashes iterator will be reset or changed by user code.

I can think of all kinds of behaviour that is totally safe with filehandles and is not safe with each(%hash). They just aren't the same thing.

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

Replies are listed 'Best First'.
Re^8: Spot the bug
by Perl Mouse (Chaplain) on Dec 22, 2005 at 11:48 UTC
    But Perl doesn't have a 'file' as datatype. Perl has filehandles. Just like it has hashes. You can have multiple filehandles, and actions on them don't interfere. You can have multiple hashes, and actions on them don't interfere either.

    And while it's true that you can open multiple handles to the same file, when was the last time you saw a program opening multiple handles on STDIN or on a socket, to name a few common streams programs read from?

    Perl --((8:>*

      You missed the point. If you have two subs that open file handles on a the same file they don't need to worry about each other. If however you have two subs that 'open' an each on the same hash, you are in serious trouble. I couldn't realy quoute you numbers on the use of either, but filehandles are certainly very different than each.


      ___________
      Eric Hodges $_='y==QAe=e?y==QG@>@?iy==QVq?f?=a@iG?=QQ=Q?9'; s/(.)/ord($1)-50/eigs;tr/6123457/- \/|\\\_\n/;print;
        No, I'm not missing the point. Unlike you, I was talking about filehandles, not files. Sure, you can open more than one handle on a file, but filehandles are used for more than files. Sockets and STDIN for instance.
        Perl --((8:>*

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2021-03-04 13:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (104 votes). Check out past polls.

    Notices?