in reply to Case-insensitive, dash-optional named parameters for your functions

I usually just do this:
use Getopt::Long; sub restart_server { my( $host, $port, $timeout ); local @ARGV = @_; GetOptions( 'host=s' => \$host, 'port=i' => \$port, 'timeout=i' => \$timeout, ); # ... }
  • Comment on Re: Case-insensitive, dash-optional named parameters for your functions
  • Download Code

Replies are listed 'Best First'.
Re^2: Case-insensitive, dash-optional named parameters for your functions
by William G. Davis (Friar) on Nov 08, 2004 at 08:57 UTC

    Very clever!

    But it only seems to support Tk-style parameters. If I call the routine without leading dashes in the parameter names, it doesn't work, nor can I make Getopt::Long ignore underscores to enable LWP-style named parameters.

    Still, very clever code reuse there.

      About the leading dashes, you can configure Getopt::Long to not require the leading dashes. Check out this thread and specifically my answer. In addition, you can do 'paramname|ParamName|param_name=i' => \$param_name to read the different styles.

        Nice.