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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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


Aug 16, 2012, 1:24 AM

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


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:

$ ./ -c a 
Name "main::secarg" used only once: possible typo at ./ 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 ./ line 25.
Shifted argument:

Can somebody help me resolve this problem? Or is in Perl some function to sort input arguments?



(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