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

Monks,

I want to pass a case-insensitive argument into a Perl script. I've used a construct like:

given( $ARGV[0] ) { when (/foo/i) {do this} when (/goo/i) {do that} }
successfully.

However, I want to add an option to each "when" whereby the passed-in value can optionally be just a number (say 0, 1, etc.). IOW, I want to be able to call the script with any of the following constructs:


perl myscript.pl foo
perl myscript.pl Foo
perl myscript.pl 0

and always "{do this}".

I tried the gw[] construct but I lose the case-insensitivity

given( $ARGV[0] ) { when (gw(/foo/i 0)) {do this} when (gw(/goo/i 1)) {do that} }
I'd appreciate some help. Thanks!

Replies are listed 'Best First'.
Re: give/when/ usage
by hippo (Archbishop) on Dec 02, 2015 at 16:46 UTC

    Is there anything wrong with:

    given( $ARGV[0] ) { when (/^(foo|0)$/i) {do this} when (/^(goo|1)$/i) {do that} }

    PS. You do know that given/when is experimental?

      Yes, I'm aware it's experimental.
      Just trying to play with it at this point - and I'm fully noob so most of what gets written is experimental anyway!
      Thanks.