Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Iterating over *any* thing in Perl

by Ovid (Cardinal)
on Dec 03, 2002 at 06:29 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://217141]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-19 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found