嗯,它看起来像您可以使用您选择的选项部分,它不会抱怨,如果它们不存在,但我没有看到任何逻辑,使相关的选项,所以你必须编写你自己逻辑。我还没有看到,会打印出任何使用功能,但你总是说
system $^X, $0, "--help";
将运行使用相同的解释($^X
)脚本($0
),它与调用,并通过它的论点--help
。这是丑陋的,但它应该工作。
=head1 OPTIONS
=over
=item --foo <foo> --bar <bar> | --foo <foo> --baz <baz>
然后使用$ARGV{'--foo'}{'foo'}
,要么$ARGV{'--foo'}{'bar'}
或$ARGV{'--foo'}{'baz'}
:
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Euclid;
sub usage {
my $message = shift;
print "$message\n\n";
system $^X, $0, "--help";
}
if (keys %ARGV) {
unless (exists $ARGV{'--foo'}) {
usage "--foo must be present if --bar or --blah is present";
exit -1;
}
if ($ARGV{'--bar'} and $ARGV{'--blah'}) {
usage "only one of --bar or --blah may be present";
exit -1;
}
}
unless ($ARGV{'--foo'}) {
print "Doing nothing\n";
exit 0;
}
print "fooing bar\n" if $ARGV{'--bar'};
print "fooing blah\n" if $ARGV{'--blah'};
__END__
=head1 NAME
foo.pl - foo the bar
=head1 VERSION
1.0
=head1 usage
foo.pl [options]
=head1 OPTIONS
=over
=item --foo
do the foo (requires --bar or --blah)
=item --bar
what to do the foo to (requires --foo)
=item --blah
what to do the foo to (requires --foo)
=item --help
=back
=head1 AUTHOR
Chas. J. Owens IV
=head1 BUGS
Hopefully none
=head1 COPYRIGHT
Copyright (c) 2009, Chas. J. Owens IV. All Rights Reserved.
This module is free software. It may be used, redistributed
and/or modified under the terms of the Perl Artistic License
(see http://www.perl.com/perl/misc/Artistic.html)