It's not clear to me what you want, since your code is wrong.

Here the correct analogous:

$ref->{foo}{$bar}

(NB: autoquoting of key "foo" !)

is

demo in the JS console

>> ref={foo: {x:42}} Object { foo: {…} } >> bar="x" "x" >> ref.foo[bar] 42 >> ref['foo'][bar] 42

as a side note, $ is a legal identifier in JS so you can also write

>> $ref={foo: {x:42}} Object { foo: {…} } >> $ref['foo'][$bar] 42

update

demo in the Perl debugger

DB<3> $ref = {foo=> { x => 42 } } DB<4> $bar = "x" DB<5> p $ref->{foo}{$bar} 42 DB<6> p $$ref{foo}{$bar} 42

update

DB<11> use experimental 'refaliasing'; \%ref = $ref DB<12> p $ref{foo}{$bar} 42

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re^2: Modules to reduce syntax? by LanX
in thread Modules to reduce syntax? by sectokia

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, details, 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, summary, 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.