in reply to Re^4: ref eq "REF"
in thread ref == "REF"

I don't now what that example is trying to show, but let's expand:

perl -l *r = ["goose"]; *r = \"moose"; print ref \*r; print ${*r}; print @{*r}; __END__ GLOB moose goose

So you see, GLOB is a useful value in this case. In anycase - if ref() returns a true value, THAT means there is something to dereference here.

Just to make it clear: ref($r) returns "REF" if $r is a reference to a reference.

On the other hand, I agree that the REF return value just adds unnesessary complexity and returning SCALAR for a ref-to-a-ref would have been more consistent and simpler (just like an arrayref returns ARRAY, and doesn't care about the elements of the array).

Replies are listed 'Best First'.
Re^6: ref eq "REF"
by gaal (Parson) on Oct 19, 2004 at 10:11 UTC
    Certainly GLOB is a useful value. The purpose of the example was to show that REF is less useful than it would seem because it is not exhaustive. Other things -- GLOBs -- can also hold references, so when writing code that decides whether to recurse further you need to either match against multiple values or call ref again anyway.