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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!perl -l use Array::RefElem qw(hv_store); my %w; my $x='foo'; hv_store(%w,'bar',$x); $w{bar}='baz'; print $w{bar}; print $x; $x='bop'; print $w{bar}; print $x; __END__ baz baz bop bop

Incidentally the difference between Array::RefElem and Lexical::Alias is that the later only does aliases between like typed items in the current pad (ie, it can make %foo an alias of %bar but it cant make $foo{$bar} an alias of $bar{bar} without making every other key/value an alias as well). Array::RefElem cant make a lexical an alias of another, but it can make the SV part of a composite object an alias to another. So in a sense the two modules complement each other nicely. Also its worth reading the docs on Lexical::Alias, it doesnt work correct under 5.6.1 and doesnt raise an error when it fails. So its essentially not safe to use pre 5.8 afaict.

And your wording is a touch ambiguous. If your question was asking how you can aliase the key part only to a variable, the answer is simple: you cant. Hash keys arent real scalars so they can't be aliased. Hash values are a different matter.


---
demerphq

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



In reply to Re: Make hash key an alias by demerphq
in thread Make hash key an alias by pope

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

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










      Results (128 votes). Check out past polls.

      Notices?