in reply to ref == "REF"

ref() returns "REF" for a reference to a reference:
> perl -e 'print ref \\"test"' REF
In general, it's not smart to rely on any specific value for ref() beside true or false, except when you really have to, i.e. for serialization. The value of ref() has changed for some types (regexes (?), filehandles...), and AFAIK there is no guarantee it won't change again.

edit: after reading perlfunc on it, it appears you can count on the return values given there (which do not cover all perl data types):

SCALAR ARRAY HASH CODE REF GLOB LVALUE and the package name for a blessed object (though you shouldn't use that)

Replies are listed 'Best First'.
Re^2: ref eq "REF"
by gaal (Parson) on Oct 18, 2004 at 10:23 UTC
    Ah yes, I realize now that there was no reason to expect

    ref \"string"

    to return anything but SCALAR, since the referred-to object was, indeed, not a reference. Thanks for the clarification.

    I'm still not sure what use REF is, though, exect perhaps as an unreliable "there is more to dereference here" indicator.

      What's unreliable about it? ref tells you "the type of thing the reference is a reference to." (quote from ref). You're used to using references to hashes and arrays (I assume), so it makes sense to you that ref(\%hash) returns HASH, since \%hash is obviously a reference to a hash. So isn't it perfectly logical (and reliable) that ref(\\$anything) returns REF, since the reference \\$anything is a reference to a reference?

      --
      edan

        Hmmm, unreliable was probably the wrong word. But (still fishing for uses for this construct) if you'r using REF as an indicator for "there's something yet to dereference here", you're in for a surprise, because it isn't a comrehensive indicator.

        *r = \"moose"; print ref \*r; # GLOB print ${*r}; # moose

        So the precise meaning of REF seems to be "a reference to something, and nothing else".

      I'm sure Data::Dumper couldn't have been written without ref to a reference returning REF.
        Why's that? It could have worked just fine if ref had returned SCALAR in this case.

        In fact, there's only place in Dumper.pm where REF is mentioned at all. Here's what it says:

        if ($realtype eq 'SCALAR' || $realtype eq 'REF')

        Clearly, Dumper would have lived just fine with "a reference is just a scalar" semantics.