Forgetting about symbolic references ( variables dynamically named ) and forgetting the above snippet, could you please explain what exactly you're trying to accomplish? It almost looks like you're trying to associate a bunch of field names with a bunch of values, and maybe trying to create variables named after those fieldnames, though the code above isn't quite doing that. With a little more explanation and clarification someone's going to come along and help you find the proper way to accomplish what you really need, instead of what you're currently asking for.

If you want to just create a bunch of variables named after the contents of @names, you would probably do it this way:

no strict qw/refs/; @::{@names} = \( @values );

But that's a surefire way to cause yourself all sorts of headaches that you really don't want to suffer through. You know, the global symbol table, that you're trying to muck around with, is just a glorified hash. If it's good enough for Perl, it's probably good enough for you too: use a hash.

UpdatedUsed a symbol-table slice instead of original foreach loop, just for fun and reckless disregard for the safety of mankind.


Dave


In reply to Re: Variable scalar creation. by davido
in thread Variable scalar creation. by snappybo

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.