in reply to RE(5): Parsing command line
in thread Parsing command line

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

Replies are listed 'Best First'.
RE(7): Parsing command line
by Tomte (Priest) on Aug 26, 2002 at 15:02 UTC
    Ok, I assume I got you wrong again...;-)

    I figured you have to overwrite @ARGV to get GetOptions to work with you local data. I played a bit with the possibility to turn $input into an array. Unfortunatly I have a meeting right now, I'll get back to it this evening, if you still need help then...

    regards,
    tomte
      I do overwrite @ARGV, I guess I missed that in my 'cut & paste':
      @ARGV = split(' ', $input);
      I have this row just before the call to parseCmdLine().

      Hotshot

        The error is, that, unlike the shell, you pass

        @ARGV is (-s, "test, drei, vier")
        for $input="-s \"test drei vier\"" (try Getopt::Long::Configure('debug');)

        I can't come up with an easy way (like one regex) to solve this, you have to parse $input a bit more complicated than the split to mimik the bash-behavior


        regards,
        tomte