Just for fun, I was playing with creating interpolated variables and attempting to actually create a series of arrays called "@array00" .. "@array09". I thought that by using "use vars", "vars->import()" I could accomplish this with strict/warnings turned on.

This was my test:

#!/usr/bin/perl use strict; use warnings; use vars; my @array_references; for(0..9) { $array_references[$_] = [1..100]; } for(0..9) { my $aname = sprintf('array%02d', $_); vars->import("\@$aname"); @$aname = @{$array_references[$_]}; } print "@array01";

Which doesn't work. If I remove the strict/warnings section, it in fact does create the arrays and work as expected.

But how do you accomplish this (regardless of whether it's stupid or not) and keep warnings/strictness?

mr.nick ...


In reply to Re: initializing multiple arrays by mr.nick
in thread initializing multiple arrays by mrc

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.