It's almost never a good idea to create variable variable names. You have to turn off use strict and you'll very likely confuse yourself.

Use a complex data structure, like a hash of arrays or array of arrays. Well, you can't literally create a hash or array of arrays, but you can do a hash/array of array references, which makes things only a bit more complex. perldoc perlreftut is a good start for learning to use references (see also perldoc perlref and tye's references quick reference), but here's some skeleton code that uses the "array of arrays" method:

# note: you could also do foreach my $d (0 .. $#arr_name) # on this loop my @Array_of_arrays; for (my $d =0; $d < $#arr_name; $d++) { # following line not necessary, but may help to # understand # what's going on: AoA[$d] is a reference to # an anonymous array $Array_of_arrays[$d] = []; # calculate the value $something2add, and push @{ $Array_of_arrays[$d] }, $something2add; }

The idea is that, for each of the values $d loops over, $Array_of_arrays[$d] holds a reference to that array. by adding the @{} around that, you de-reference that value (i.e. get the array that it refers to).

Hope this gets you started.

perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

In reply to Re: Varying Variable Names by arturo
in thread Varying Variable Names by willick

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.