Modifies @ARGV by replacing a certain option (with or without argument) with something else. Uses Getopt::Long.
In my application, which takes a list of filespecs on the commandline, I replace -tar foo.tar with /tmp/tar/* after having extracted foo.tar into /tmp/tar/:
The first arg is the sort of thing you pass as an option spec to Getopt::Long's GetOption().option_replacement( "tar=s", sub { system "tar xf $_[1] -C $tmpdir"; " +$tmpdir/*" } );
use Getopt::Long; sub option_replacement { my( $spec, $func ) = @_; local $Getopt::Long::passthrough=1; my @newARGV; GetOptions( $spec => sub { push @newARGV, &$func }, '<>' => sub { push @newARGV, @_ }, ); @ARGV = @newARGV; }
|
|---|