Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: Make hash key an alias

by demerphq (Chancellor)
on Nov 18, 2003 at 15:38 UTC ( #308002=note: print w/replies, xml ) Need Help??


in reply to Re: Make hash key an alias
in thread Make hash key an alias

Well, the way I read this its actually wrong. (UPDATE: and calin said as much, although in a way that may not be immediately apparent to readers unfamiliar with Lexical::Alias, so I still feel this node is worthy, if only to expand on what is happening here.) In this you arent making $h{key} an alias to $s. You are making $s be an alias to $h{key}. Not the same thing. Use Array::RefElem and you dont have this problem, and can do it with either lexicals or globals. (Making the composite type contain an alias to an arbitrary Scalar that is.)

use Lexical::Alias qw(alias_r); my ($s, %h); print '$s:',\$s, "\n", '$h{key}:',\$h{key}, "\n"; print "---\n"; alias_r \$h{key}, \$s; print '$s:',\$s, "\n", '$h{key}:',\$h{key}, "\n"; __END__ $s:SCALAR(0x1ac2430) $h{key}:SCALAR(0x1acefd4) --- $s:SCALAR(0x1acefd4) $h{key}:SCALAR(0x1acefd4)

Come to think of it IMO its ridiculous all these different modules with weirdo names having alias related tools in them. I think this calls for a consolodation release with them all in one place... (broquaint are you listening?)


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi


Replies are listed 'Best First'.
Re: Re: Re: Make hash key an alias
by calin (Deacon) on Nov 18, 2003 at 16:31 UTC
    Well, the way I read this its actually wrong. In this you arent making $h{key} an alias to $s. You are making $s be an alias to $h{key}. Not the same thing.

    Re-read my post. Clearly stated the other way around. The OP decides if that suits him.

    You're right that Array::RefElem is the best solution. I didn't know about that module.

      Ahem. Caugh. Yes. It seems the meaning of those words didnt penetrate my thick skull. Apologies.


      ---
      demerphq

        First they ignore you, then they laugh at you, then they fight you, then you win.
        -- Gandhi


Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2020-02-21 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (94 votes). Check out past polls.

    Notices?