Hello again, Monks. I have a question for the collective genius of this monastery. I have googled for it, but I think I'm not asking google the right question. Here goes:

In my code, I have a piece that evaluates to a numeric value, either 4 or 6. In my test code snippet below, I am simply assigning the value statically for testing purposes. I want to use the value of this scalar in the name of an array further down in my code, so I can avoid "if else" blocks. However, this isn't working. I have read sites where the general consensus is that dynamic variable names are a bad idea, but based on the code that went along with those posts, I am not sure they apply to my situation. On to my code snippet:

#!C:/Perl64/bin/perl.exe use strict; use warnings; use Control::CLI; my $cli; my $output; my $temp; my $junk; my $port; my $result; my @STATION_LIST_6 = qw/A B C D E F/; my @STATION_LIST_4 = qw/A B C D/; ... my $STATION_CNT = 4; my $FREEMEM; print "Configuring blah blah blah...\n"; print "\tChecking free memory on appropriate blades to ensure there is + enough for application execution...\n"; foreach my $stid (@STATION_LIST_$STATION_CNT) { <-- This line doesn't + work... $junk = $cli->print("echo STATION_\$stid; su -c \"ssh STATION_\$st +id free -g\""); $output = $cli->cmd("password"); $FREEMEM = $output =~ m/^.*?\w+:\s+\d+\s+\d+\s+(\d+)\s.*$/s if ( $FREEMEM >= 4 ) { print "\t\tSTATION_$stid reports sufficient free memory...\n"; } else { print "\t\tSTATION_$stid reports insufficient free memory ($FR +EEMEM)... Please investigate and start application again... Exiting p +rogram.\n"; exit; } }

If anyone has any thoughts they could share, I would appreciate it. I REALLY want to avoid "if else" here, and dynamically figure out the value of the array to use. Thanks in advance, as always!


In reply to Using Scalar In Array Name? by ImJustAFriend

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.