Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Iterating over *any* thing in Perl

by Ovid (Cardinal)
on Dec 03, 2002 at 06:29 UTC ( #217141=note: print w/replies, xml ) Need Help??


in reply to Iterating over *any* thing in Perl

Typically (not always), you can inspect the contents of anything, but that depends upon how you define "contents". For example, what do you mean when you say "the content of a closure"? If you wanted, as I believe you were describing, to remove an internal reference to an external object, then you would probably just undef the scalar holding the reference to the closure or have the closure internally undef an unnecessary reference. There's no way (and no need) to peer inside. As for objects, are you referring to a need to iterate over what data structure has been blessed? You can bless hash references, an array references and those are easy to iterate over. However, how would you "iterate" over a code reference or a regex that's been blessed?

As for a general function to access each field of an object, there isn't one. This is something that is (and should be!) handled inside of the object's class and is based upon the needs of that particular object. For example, I once found a solution to a thorny problem by blessing integers. One doesn't typically iterate over a single value if you know it's always a single value.

Cheers,
Ovid

New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2021-05-14 20:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (150 votes). Check out past polls.

    Notices?