
waldauf
Novice
Aug 16, 2012, 1:24 AM
Post #1 of 5
(1215 views)
|
|
[SOLVED]Problem with saving argument from input @ARGV to scalar
|
Can't Post
|
|
Hello, I run perl script with input arguments from command line. At first I recognize first argument and then I would like to save second argument of @ARGV array to scalar variable. But I have problem with saving in SWITCH-CASE structure:
#!/usr/bin/perl -w # Using SWITCH (case) statment use Switch; foreach my $arg (@ARGV) { print "Input arguments: @ARGV\n"; print "Actual argument: $arg\n"; print "Second argument: $ARGV[1]\n\n"; switch ($arg) { case "-c" { print "Actual argument $arg\n"; print "Second argument: $ARGV[1]\n"; my $secarg = $ARGV[1]; #my $secarg = shift (@ARGV); print "Shifted argument: $secarg"; } else { print "Unknown argument: $arg\n"; } } print "End of cycle.\n\n"; } print "Shifted argument: $secarg"; And result which I see in command line:
$ ./test.pl -c a Name "main::secarg" used only once: possible typo at ./test.pl line 25. Input arguments: -c a Actual argument: -c Second argument: a Actual argument -c Second argument: a Shifted argument: aEnd of cycle. Input arguments: -c a Actual argument: a Second argument: a Unknown argument: a End of cycle. Use of uninitialized value in concatenation (.) or string at ./test.pl line 25. Shifted argument: Can somebody help me resolve this problem? Or is in Perl some function to sort input arguments? Thx, Waldauf
(This post was edited by waldauf on Aug 16, 2012, 4:52 AM)
|