I would like to declare variables recursively, this way I could save lots of time in associating data of arrays hashes etc. What I would like to to is the following: foreach $name (@array){ ${$name}=X } is it possible con perl?, because its posible with linux shell. Thanks
  1. yes, it's possible, and it fundamentally amounts to accessing the keys of one particular, special hash, namely the symbol table. These animals are called "symbolic references" (or more shortly, "symrefs").
  2. since you're manipulating a hash, just use a "real", generic one:
    $hash{$_} = X for @array;
    takes only a few more keystrokes... (well, actually less, but that's only because I used for as a statement modifier.)

    In particular there are tons of mails/posts/nodes/articles explaining why it is generally recommended not to use symrefs, which is also the reson why they're ruled out by use strict; (hey, you're using it, aren't you?)

  3. WRT "is it possible con perl": in inglese dovresti usare "with" ;-)

      In reply to Re: Declaring variables recursively by blazar
      in thread Declaring variables recursively by sciarnold

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



    1. Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
    2. Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
    3. Read Where should I post X? if you're not absolutely sure you're posting in the right place.
    4. Please read these before you post! —
    5. 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
    6. 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;
    7. Link using PerlMonks shortcuts! What shortcuts can I use for linking?
    8. See Writeup Formatting Tips and other pages linked from there for more info.