in reply to How to parse these command-line options?
A bit more clever code could avoid having file2 and file3 treated as seperate arguments but as a list. Anyway, hth...use Getopt::Long; use Data::Dumper; use strict; my %opts=(a=>0,b=>0,c=>0); sub process_file { my ($opts,$file)=@_; print "Processing $file "; print join ", ", map { "$_ => $opts{$_}" } keys %opts; print "\n"; } Getopt::Long::Configure('require_order'); while (@ARGV) { #print Data::Dumper->Dump([\%opts,\@ARGV],[qw(*opts ARGV)]); GetOptions(\%opts,qw(a! b! c!)); if (@ARGV) { my $file=shift; process_file(\%opts,$file); } } __END__ >perl gopt2.pl file0 -a file1 --noa --b file2 file3 --c file4 --nob fi +le5 Processing file0 a => 0, b => 0, c => 0 Processing file1 a => 1, b => 0, c => 0 Processing file2 a => 0, b => 1, c => 0 Processing file3 a => 0, b => 1, c => 0 Processing file4 a => 0, b => 1, c => 1 Processing file5 a => 0, b => 0, c => 1
--- demerphq
my friends call me, usually because I'm late....
|
|---|