Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^4: ref == "REF"

by gaal (Parson)
on Oct 18, 2004 at 20:39 UTC ( [id://400314]=note: print w/replies, xml ) Need Help??


in reply to Re^3: ref == "REF"
in thread ref == "REF"

I hope I understand you correctly. If so, then wouldn't the expression

ref $x eq 'SCALAR' && ref $$x

suffice as an idiomatic substitute for the current

ref $x eq 'REF'

?

Replies are listed 'Best First'.
Re^5: ref == "REF"
by Anonymous Monk on Oct 18, 2004 at 21:15 UTC

    Thinking about it some more made me realize that ref $x eq 'REF' can be used more efficiently then ref $x eq 'SCALAR'. (Although not really on the previous code, since the goal was to keep one reference at the end)

    If you have ref $x eq 'REF' then you know that the scalar to which $x refers to is yet another reference, so noone stops you from doing $x = $$$x;, which avoids yet another call to the ref function...

Re^5: ref == "REF"
by Anonymous Monk on Oct 18, 2004 at 21:00 UTC
    Yes it would.

    But then you are doing two calls to ref instead of one...

    But then another question would be, which one would be the most efficient? (assuming the perl-interpreter does not return REF (and doesn't do any check on it))

      The current behavior would be the more efficient one. But it is also less clean, conceptually, so (I'm come to conclude) it shouldn't belong in the ref builtin.

      This doesn't matter, though. It is a *very simple extension* to add this feature outside core perl. Something along the lines of:

      use Inline C => << "EO_REFREF"; int refref(SV* thing) { return SvROK(SvRV(thing)); } EO_REFREF
      (This is not anywhere near tested, though :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-24 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found