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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |