Dear Monks,

I need to declare a lot of variables in the following way:
my $abc_this_01 = "C:/Stuff/abc_this_01.csv"; my $def_this_01 = "C:/Stuff/def_this_01.csv"; my $ghi_this_01 = "C:/Stuff/ghi_this_01.csv"; my $jkl_this_01 = "C:/Stuff/jkl_this_01.csv"; my $mno_this_01 = "C:/Stuff/mno_this_01.csv"; my $abc_this_02 = "C:/Stuff/abc_this_02.csv"; my $def_this_02 = "C:/Stuff/def_this_02.csv"; my $ghi_this_02 = "C:/Stuff/ghi_this_02.csv"; my $jkl_this_02 = "C:/Stuff/jkl_this_02.csv"; my $mno_this_02 = "C:/Stuff/mno_this_02.csv"; # ... my $abc_that_01 = "C:/Stuff/abc_that_01.csv"; my $def_that_01 = "C:/Stuff/def_that_01.csv"; my $ghi_that_01 = "C:/Stuff/ghi_that_01.csv"; my $jkl_that_01 = "C:/Stuff/jkl_that_01.csv"; my $mno_that_01 = "C:/Stuff/mno_that_01.csv"; # etc.
I thought if it were possible to initialize the variables per loop. My knowledge in Perl however is definitely not good enough to manage this.
I tried it like this:
use strict; use warnings; my @component = qw / abs def gki jkl mno /; for (@component) { my $comp = $_; our ${$comp.'_this_01'} = "C:/Stuff/${_}_this_01.csv"; }
but it seems to be fundamentally wrong.
Could you give me an advice?
Thanks in advance.
VE

In reply to How to declare variables per loop by Anonymous Monk

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.