in reply to Parsing command line

It is nearly impossible to find an error without the code. are you sure you read perldoc Getopt::Long thouroughly?

my $s = ''; GetOptions('string=s' => \$s);

should normaly do what you want (it does for me). Maybe you forgot to pass your variable as a reference?


regards,
tomte

Replies are listed 'Best First'.
Re: Re: Parsing command line
by hotshot (Prior) on Aug 26, 2002 at 13:02 UTC
    I did exactly the same as you, here is it:
    local %hash; if (GetOptions(\%hash, 'pdcuse!', 'uamlist=s', 'loginmesg=s')) { &doSomething(); }
    as you can see I used hash (reference), but doesn't supposed to matter (it happened to me even when I didn't used hash).

    Hotshot
      use Getopt::Long; use strict; use warnings; use Data::Dumper; my %hash; GetOptions(\%hash, 'pdcuse!', 'uamlist=s', 'loginmesg=s'); print "" . Dumper(\%hash) . "\n"; __END__ perl test.pl -u "test eins zwei drei" -l "test drei vier fuenf" -p yields: $VAR1 = { 'pdcuse' => 1, 'uamlist' => 'test eins zwei drei', 'loginmesg' => 'test drei vier fuenf' };

      using local instead of my doesn't alter the result, it simply works...(older SuSE, bah, perl 5.6.1)
      So I'm out of luck here...
      regards,
      tomte


        My fault, I wasn't clear enough. I wrote a command line interface to our product in my company. The parsing isn't working with spaces within it. from the Linux shell command line it works.
        Linux prompt>myprog Welcome to my program !!! myprog prompt> set -message "hello world" # this doesn't work
        I hope now the question is clearer.

        Hotshot