CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: [SOLVED]Problem with saving argument from input @ARGV to scalar: Edit Log



waldauf
Novice

Aug 16, 2012, 1:24 AM


Views: 1653
[SOLVED]Problem with saving argument from input @ARGV to scalar

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:


Code
#!/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:

Code
$ ./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)


Edit Log:
Post edited by waldauf (Novice) on Aug 16, 2012, 4:52 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives