in reply to Re: Problem passing a string in system function
in thread Problem passing a string in system function

I use Getop::Long to get the argument.
I've looked at @ARGV, it gives:
$VAR1 = [ '-type', 'sugar', '-unit', '6' ]; # where $sometype = 'foo'; $some_unit = 6;
So as you can see EMAIL option and its value is totally unrecognize here.
My overall construct under 'mycode.pl' looks like this:
use strict; use Data::Dumper; use Getopt::Long; print Dumper \@ARGV ; my $type = 'bar'; my $no_unit = 1; my $help = 0; my $tg_email = ''; if ( @ARGV == 0 ) { &usage(); exit(1); } my $res = GetOptions ( "type=s"=>\$type, "unit=i"=>\$no_unit, "email=s"=>\$tg_email, "help"=>\$help,); if ($res) { print "$tg_email\n" # show nothing here. # and do some other thing }

Replies are listed 'Best First'.
Re^3: Problem passing a string in system function
by blazar (Canon) on May 19, 2006 at 10:57 UTC

    How strange! Running the following with no arguments

    #!/usr/bin/perl -l use strict; use warnings; use Data::Dumper; if (@ARGV) { print Dumper \@ARGV; } else { my $email = 'myemail@gmail.com'; system "$0 -email $email"; print '-' x 20; system $0, -email => $email; } __END__

    I get:

    $VAR1 = [ '-email', 'myemail@gmail.com' ]; -------------------- $VAR1 = [ '-email', 'myemail@gmail.com' ];