Is there anyway to allow the use of a variable in the making of an array name? I really need it for this foreach loop:
#!/usr/bin/perl5 use strict; use warnings; use diagnostics; # Load Module use HLDS; my @games=qw( cstrike dod czero gearbox ricochet dmc tfc valve ); foreach my $game (@games) { my @maps_$game = HLDS::GameMaps("$game"); }
I need it to go through each element in the @game array and create an array named @maps_gamename based on the elements ont the array. However I keep receiving the following errors telling me I left semicolons off, I did not. Errors:
Scalar found where operator expected at 6.pl line 14, near "@maps_$gam +e" (#1) (S) The Perl lexer knows whether to expect a term or an operator. + If it sees what it knows to be a term when it was expecting to see an operator, it gives you this warning. Usually it indicates that an operator or delimiter was omitted, such as a semicolon. Scalar found where operator expected at 6.pl line 14, near "@maps_$gam +e" diagnostics::warn_trap('Scalar found where operator expected a +t 6.pl line 14, near "@...') called at 6.pl line 14 (Missing operator before $game?) (Missing operator before $game?) diagnostics::warn_trap('\x{9}(Missing operator before $game?)\ +x{a}') called at 6.pl line 14 syntax error at 6.pl line 14, near "@maps_$game " Global symbol "%class" requires explicit package name at 6.pl line 14. Execution of 6.pl aborted due to compilation errors (#2) syntax error at 6.pl line 14, near "@maps_$game " Global symbol "%class" requires explicit package name at 6.pl line 14. Execution of 6.pl aborted due to compilation errors. diagnostics::death_trap('syntax error at 6.pl line 14, near "@ +maps_$game "\x{a}Global symb...') called at 6.pl line 16

In reply to Re^2: Perl Module Problems by davidov0009
in thread Perl Module Problems by davidov0009

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.