in reply to Re: Passing switches through pl2bat scripts
in thread Passing switches through pl2bat scripts

you are setting the value of %opt{z} == "" which is false.

Actually I disagree. The documentation says quite clearly that this behaviour is incorrect:

The getopt() functions processes single-character switches with switch clustering. Pass one argument which is a string containing all switches that take an argument. For each switch found, sets $opt_x (where x is the switch name) to the value of the argument, or 1 if no argument. Switches which take an argument don't care whether there is a space between the switch and the argument.

Although I do agree with you that probably he should be using getopts and not getopt, but even better would be to just ditch Getopt::Std and use Getopt::Long instead.


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi


Replies are listed 'Best First'.
Re:^3 Passing switches through pl2bat scripts
by flounder99 (Friar) on Nov 17, 2003 at 17:17 UTC
    But getopt always assumes all the named switches take arguments.
    getopt('oDI'); # -o, -D & -I take arg. Sets $opt_* as a side e +ffect. getopt('oDI', \%opts); # -o, -D & -I take arg. Values in %opts
    Try running this:
    #!perl use Getopt::Std; my %opts = (); getopt('z', \%opts); for (keys %opts) { print '$opts{', $_, '} = "', $opts{$_}, "\"\n"; }
    you get some interesting results
    C:\myperl\temp>perl temp.pl -z $opts{z} = "" C:\myperl\temp>perl temp.pl -y $opts{y} = "1" C:\myperl\temp>perl temp.pl -y -z $opts{y} = "1" $opts{z} = "" C:\myperl\temp>perl temp.pl -z -y $opts{z} = "-y" C:\myperl\temp>temp -z -z $opts{z} = "-z"

    --

    flounder

      Something is wrong. Either the documentation, or the code. The documentation clearly states that the value of a valueless option is to be set to be 1. It does not actually happen. Thus there is an error involved here. Generally the rule is that the code should fit the docs, so I assume the code is buggy. Anyway, ive sent a patch to p5p.


      ---
      demerphq

        First they ignore you, then they laugh at you, then they fight you, then you win.
        -- Gandhi