Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: How to dereference a FORMAT reference?

by Jeffrey Kegler (Hermit)
on Jun 24, 2009 at 00:52 UTC ( [id://774207]=note: print w/replies, xml ) Need Help??


in reply to Re: How to dereference a FORMAT reference?
in thread How to dereference a FORMAT reference?

That's a very good idea, and one I hadn't thought of.

But it's just half the problem. The solution requires that I know the typeglob slot. All I have is a reference and I don't know a general way of going from the reference to the typeglob slot.

In fact, I can't see from the documentation any situation in which a format reference can be used for any purpose whatsover. (Unless you count taking its address and using that as a very low quality pseudo-random number generator as a "use".)

Replies are listed 'Best First'.
Re^3: How to dereference a FORMAT reference?
by tye (Sage) on Jun 24, 2009 at 06:35 UTC
    All I have is a reference and I don't know a general way of going from the reference to the typeglob slot.

    What? I thought that the typeglob slots were chosen to match what ref returns (except you'd want Scalar::Util::reftype because of the unfortunate decision to overload ref to returning class names and you have to deal with just a few special cases like the unfortunate and silly decision to have ref(\\$x) return "REF" instead of "SCALAR" and the more reasonable features of returning "LVALUE" or "VSTRING" instead of "SCALAR").

    I don't see how having to deal with 3 special cases prevents this from being a "general" solution.

    Updated with minor wording changes.

    - tye        

Re^3: How to dereference a FORMAT reference?
by morgon (Priest) on Jun 24, 2009 at 15:32 UTC
    I think it is even simpler:

    Consider:

    use strict; use Scalar::Util qw(weaken isweak); my $a = []; my $r1 = $a; my $r2 = $a; weaken $r1; print "a is weak\n" if isweak $a; print "r1 is weak\n" if isweak $r1; print "r2 is weak\n" if isweak $r2;

    So here we have a array_ref $a of which we make two further copies for which we prove again that they are different.

    So to answer your initial question:

    Given a reference you simple assign it to a scalar to get another reference to the same referent - no need for special syntax or type-glob fiddling...

      You're 100% right. It's so simple and obvious that I never suspected. Thanks.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-03-28 18:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found