Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Missing ref() return possibility?

by BrowserUk (Pope)
on May 16, 2008 at 01:34 UTC ( #686835=perlquestion: print w/replies, xml ) Need Help??

BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:

Perlfunc lists the following possible return values from ref:

SCALAR ARRAY HASH CODE REF GLOB LVALUE

Is that all of them? I've got a vague recollection of either encountering or seeing reference to a 'REGEX' type?

Any others?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re: Missing ref() return possibility?
by toolic (Bishop) on May 16, 2008 at 01:45 UTC
    ref lists these:
    SCALAR ARRAY HASH CODE REF GLOB LVALUE FORMAT IO VSTRING Regexp
Re: Missing ref() return possibility?
by rhesa (Vicar) on May 16, 2008 at 01:42 UTC
    The types you list are the basics. All other cases are covered by "If the referenced object has been blessed into a package, then that package name is returned instead."

    For regular expressions, this is demonstrated by:

    use Scalar::Util qw/blessed/; $q=qr//; print ref($q); print blessed($q); __END__ Regexp Regexp

      What your code implies but isn't quite explicit about is that qr() actually gives back a blessed reference to a scalar.

      use Scalar::Util qw/blessed reftype/; my $q = qr//; print 'ref: ', ref($q), "\n"; print 'blessed: ', blessed($q), "\n"; print 'reftype: ', reftype($q), "\n"; __END__ ref: Regexp blessed: Regexp reftype: SCALAR

      There's some more about this in How can I tell if an object is based on a regex?

Re: Missing ref() return possibility?
by Fletch (Chancellor) on May 16, 2008 at 01:47 UTC

    qr// will return an instance that ref returns Regexp for; perhaps that's what you're remembering?

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Missing ref() return possibility?
by runrig (Abbot) on May 16, 2008 at 01:44 UTC
    Did you try perl -e 'print ref(qr/abc/)' ??
Re: Missing ref() return possibility?
by graff (Chancellor) on May 16, 2008 at 05:36 UTC
    It's good to remember that when ref() is given something that is not a reference to anything, it returns an empty string. (It never seems to return "undef", even when you give it nothing at all.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2021-12-02 01:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (16 votes). Check out past polls.

    Notices?