in reply to array confusion
You could simplify this as follows:$system1 = <STDIN>; # this is manual input from the keyboard #... $system1 =~ s/\W.*//; # what if input was " box1" (initial space)? #...
(By including the "s" modifier on the substitution, you don't need to do "chomp", because the ".*" will match the final new-line.)( $system1 = <STDIN> ) =~ s/^\W*(\w+).*/$1/s;
But personally, I always prefer to get this sort of user input from the command line, via @ARGV. Programs that start up, then pause, print a prompt and wait until something gets typed at the keyboard are such a pain.
my %systems = ( box1 => 1, box2 => 2 ); my $Usage = "Usage: $0 (" . join('|', sort keys %systems) . ")\n"; die $Usage unless ( @ARGV == 1 and $systems{$ARGV[0]} ); $system1 = lc( shift );
|
|---|