in reply to Re: Re: Parsing command line
in thread Parsing command line

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


Replies are listed 'Best First'.
Re: Re: Re: Re: Parsing command line
by hotshot (Prior) on Aug 26, 2002 at 13:46 UTC
    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
      I hope now the question is clearer.

      Not really ;-)
      is myprog a shell-script, that starts perl-programs or a perl-program internally using input via STDIN to feed Getopt::Long?

      I'm sorry to say, more than ever: without actual code with the right context, I for one can't help you any further,

      If it is a bash-script calling a perl-script, it's with a high probability a quoting-problem.
      regards,
      tomte


        sorry again, myprog is a perl script that starts ap perl program using input via STDIN as you said.
        here is some more code:
        # main perl script my $input; # defining ReadLine module for supporting my $term = new Term::ReadLine 'Command Line Interface'; print "\nWelcome to my command line interface (version $version)!\n\n" +; while (defined($input = $term->readline("\n" . $prompt.' (main, exit, +back, help) > '))) { chomp $input; $input =~ s/^\s+//; # delete leading spaces $input =~ s/\s+$//; # delete trailing spaces &parseCmdLine(); ... } sub parseCmdLine { ... local %hash; if (GetOptions(\%hash, 'netbios=s', 'winbind!', 'srvstring=s')) { &doSomething(); } ... }


        Hotshot