in reply to Re: getOptions() parse problem
in thread getOptions() parse problem

Ok, that works, thanks, but is there no other way to let getOptions ignore -10 as an options. Because I would like to use both - and --, like:
    > myPerl.pl -n -10
or
    > myPerl.pl --number -10

Both represent the same thing! So in case I only use -- I have to use --n, to me that doesn't look right!!

Any comments on this ?
Thanks
Luca

Replies are listed 'Best First'.
Re^3: getOptions() parse problem
by gargle (Chaplain) on Sep 13, 2005 at 09:32 UTC

    Hi again,

    I see you declare your 'option' as an optional string (:s):

    $getoptret = $p->getoptions( 'number:s' =>\$num, .......) ;

    try to change it in a mandatory integer:

    $getoptret = $p->getoptions( 'number=i' =>\$num, .......) ;

    According to the camel book:

    =i
    Option takes a mandatory integer argument. This value will be assigned to the option variable. Note that the value may start with - to indicate a negative value.
    --
    if ( 1 ) { $postman->ring() for (1..2); }
      You're right again, but what if
         > myPerl.pl -n "-10 20 .9388"
      
      This time it doesn't work!!
      Luca

        Hi,

        So -n isn't a number but an angle? In that case you'd have to use =s as there is no other way to represent an angle (except for floating point format but I guess you're not looking forward of having to type -n 5.383837233838.

        Or you could use -d for decimals (--degrees), -m for minutes (--minutes) and -s for seconds (--seconds) as an alternative format to input your angle.

        When using =s you need to use the double dash to seperate your 'negative' values from the other options.

        You have to make a choice about the format you are willing to use :)

        --
        if ( 1 ) { $postman->ring() for (1..2); }