#!/usr/bin/perl -w
use strict;
use Getopt::Declare;
my $spec = <<'SPEC';
# put your specification here
SPEC
my $ops = Getopt::Declare->new($spec);
# rest of your program
####
#!/usr/bin/perl -w
use strict;
use Getopt::Declare;
use vars qw/$not $re/;
$::VERSION = 0.01;
my $spec = <<'EOS';
-p pattern [required]
{ $re = $pattern }
-f ... input filename(s) [required]
{ defer{process(@INFILE)} }
-not print out non-matches
{ $not = 1 }
EOS
my $opts = Getopt::Declare->new($spec);
sub process {
@ARGV = @_;
while(<>){
if($::not){
print unless /$::re/;
} else {
print if /$::re/;
}
}
}
__END__
##
##
-f ...
# So we specify an option that looks like '-f' which takes one or
# more arguments (that's the ... part) that will be stored in the
# variable @INFILE for the action block
input filename(s) [required]
# This is the description of the option followed by the
# [required] directive which means this option must be present on
# the command line
{ defer{process(@INFILE)} }
# This is the action block. The defer() function is from
# Getopt::Declare and takes a code block which will not be
# executed until all the command line options have been parsed.
# Here we merely provide our own function and pass it the files
# from the -f option as arguments.
##
##
-p # accept strings
-n # accept any real number
-i # accept only integers
##
##
-hw HeightxWidth coordinates
#or
[pvtype: coord /\d+x\d+$]
-hw HeightxWidth coordinates
##
##
$ perl dopt.pl -v
dopt.pl: version 0.01 (Fri Feb 2 09:30:34 2001)
$ perl dopt.pl -help
Usage: dopt.pl [options] -p -f ...
dopt.pl -help
dopt.pl -version
Options:
-p pattern
-f ... input filename(s)
-not print out non-matches