
Karazam
User
Feb 1, 2011, 10:45 AM
Post #2 of 5
(704 views)
|
|
Re: [Alpinesun] Would like some advice on the best way to approach this issue
[In reply to]
|
Can't Post
|
|
So basically I think you want something like
print "Please enter the device number (001 etc) "; my @switchnums = split /\s+/, <>; for my $x ( @switchnums ) { # see if it works print "$x\n"; } (<> has the same meaning as <STDIN>) One quirk with this is, that if the user puts blank space before the first argument, you'll wind up with an empty first element in the array. To fix this, you can
print "Please enter the device number (001 etc) "; my $line = <>; $line =~ s/^\s+|\s+$//g; # remove leading and trailing white space my @switchnums = split /\s+/, $line; for my $x ( @switchnums ) { # see if it works print "$x\n"; } Of course you might want to check that the input is sane in other ways before proceeding, but that's another matter. Hope this helps.
(This post was edited by Karazam on Feb 1, 2011, 10:48 AM)
|