This seems like a parse error, but it's hard to say that the current behavior isn't intentional. Here are a few similar snippets, and how they deparse with -MO=Deparse,x9:

use strict; use warnings; my $pic = 1; my $v = {R3R3_1_IF => 100}; print "Hello world. $v->{R3R3_$pic\_IF}\n";

The output with perl -MO=Deparse,x9 mytest.pl:

Backslash found where operator expected at mytest.pl line 9, near "$pi +c\" (Missing operator before \?) Bareword "_IF" not allowed while "strict subs" in use at mytest.pl lin +e 9. mytest.pl had compilation errors. use warnings; use strict; my $pic = 1; my $v = {'R3R3_1_IF', 100}; print "Hello world. $$v{$pic->R3R3_(\'_IF')}\n";

If you attempt to disambiguate using curly braces it still fails:

use strict; use warnings; my $pic = 1; my $v = {R3R3_1_IF => 100}; print "Hello world. $v->{R3R3_${pic}_IF}\n";

The output...

Bareword found where operator expected at mytest.pl line 9, near "${pi +c}_IF" (Missing operator before _IF?) Bareword "_IF" not allowed while "strict subs" in use at mytest.pl lin +e 9. mytest.pl had compilation errors. use warnings; use strict; my $pic = 1; my $v = {'R3R3_1_IF', 100}; print "Hello world. $$v{$pic->R3R3_('_IF')}\n";

In both cases the interesting deparse to me is $pic->R3R3_('_IF'), and the explanation appears to be that the parser seems to feel this is a fine time to see the construct as indirect object notation.


Dave


In reply to Re: variable inside hash key by davido
in thread variable inside hash key by Anonymous Monk

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.