fxia has asked for the wisdom of the Perl Monks concerning the following question:

Hi, My question is probably an old one. Unfortunately I was not able to find any answers. Basically, how can I break up the command line into an array of arguments? For example:
cmd123 a 'b c' 'd e f'
should have three arguments (a, 'b c', 'd e f'). What would be a good way of doing it? Thanks a lot!!!

Replies are listed 'Best First'.
Re: Break up command line
by dl748 (Initiate) on Jun 02, 2001 at 02:35 UTC
    I thought when you execute the script it automatically puts it in @_. So when you first start the script you can
    $firstele = shift; $secondele = shift; $thirdele = shift;
    or you can do it this was
    my ($first, $second, $third) = @_;
    so if you run a command like this
    myscript.pl "this is a test" what is it
    $first = "this is a test" $second = "what" $third = "is"

    does this help?
      Almost, you want @ARGV, not @_

      Jeff

      R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
      L-L--L-L--L-L--L-L--L-L--L-L--L-L--
      
        interesting. @_ works on sco, and (caldera, red hat) linux.
Re: Break up command line
by Desdinova (Friar) on Jun 02, 2001 at 12:40 UTC
Discard - Re: Break up command line
by fxia (Novice) on Jun 02, 2001 at 02:26 UTC
    Sorry for my lazyness. Just flipped through the cookbook. THe answer is there with Text::ParseWords.