in reply to getting args without clobbering @ARGV

I have used Getopt::Long for years, and it doesn't seem very "clunky and difficult to manage", but it could just be me. Here's how I'd do that:

use Getopt::Long; my $debug = 0; # Optional parameters (removed from @ARGV) GetOptions( 'debug' => \$debug, ); # Positional parameters (left in @ARGV) my ($infile) = @ARGV;

Update: replaced code ref with simple scalar ref to flag variable

Update: a few minor points:

Replies are listed 'Best First'.
Re^2: getting args without clobbering @ARGV
by bfdi533 (Friar) on May 11, 2006 at 20:13 UTC

    Thanks for the suggestion and for the sample code.

    For me I guess "clunky and difficult to manage" comes from the Camel book, pages 452-453 where, using getops you have something like:

    my $debug = 0; getopt('dlv'); if ($opt_d) { $debug = 1; } if ($opt_l) { # do something with arg l } if ($opt_v) { # do something with arg v }

    To me that is not very managable. I can see from your code example and from the CPAN docs for Getopt::Long that this might actually be more workable for me.

    I presume that I have to set some sort of option to be able to use "-d" rather than "-debug"?

      Even better, you can support both with a simple

      GetOptions( 'debug|d' => \$debug, );


      Xaositect - Whitepages.com