in reply to Problem passing a string in system function

There doesn't seem to be any good reason why that wouldn't work.

How are you accessing the arguments inside mycode.pl? Have you tried looking at the contents of @ARGV as soon as the program starts up?

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

  • Comment on Re: Problem passing a string in system function

Replies are listed 'Best First'.
Re^2: Problem passing a string in system function
by Anonymous Monk on May 19, 2006 at 10:40 UTC
    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 }

      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' ];