The problem really has nothing to do with string interpolation as your node title asserts. It actually should be giving you the following error.

Can't declare scalar dereference in my at mytest.pl line 7, near "} =" Execution of mytest.pl aborted due to compilation errors.

The error is because you're trying to declare a lexical variable with 'my' that is a dereferenced symbolic reference. That just doesn't make sense.

What all that means is that you cannot use a symbolic reference as the name of a lexically declared variable. The fact is that lexical variables can't be referred to symbolically. All symbolic refs refer to package globals.

See perlref for details. Also take note that in 99.9% of the common-code situations, you don't really need to be thinking in terms of symbolic references anyway. You can almost always accomplish what your objective is more cleanly with a lexical. If you're interested in "variable names", try using a hash instead, where the keys are represented by those names instead of mucking around in the global symbol table. The global symbol table is, after all, just a glorified hash.


Dave


In reply to Re: String interpolation problem by davido
in thread String interpolation problem by rockmountain

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.