| Filter::Arguments - Configure and read your command line arguments from @ARGV. |
Filter::Arguments - Configure and read your command line arguments from @ARGV.
use Filter::Arguments;
my $solo : Argument(bool) = 1; my $bool_default : Argument; my ($a,$b,$c) : Arguments(bool); my ($d,$e,$f) : Arguments(value); my ($x,$y,$z) : Arguments(xbool); my ($three,$four,$five) : Arguments(value) = (3,4,5); my ($six,$seven,$eight) : Arguments(bool) = ('SIX','SEVEN','EIGHT');
my $multiline : Argument(value) = <<END_ML; my multi-line initial value END_ML
my @result = ( $solo, $bool_default, $a, $b, $c, $d, $e, $f, $x, $y, $z, $three, $four, $five, $six, $seven, $eight, $multiline, );
print join ',', @result;
if invoked as: $ script.pl --solo --a --b --c --d A --e B --f C --x --y --z --six
will print:
0,,1,1,1,A,B,C,0,0,1,3,4,5,0,SEVEN,EIGHT,my multi-line initial value
Here is a simple way to configure and parse your command line arguments from @ARGV. If an unrecognized argument is given then a basic usage statement is printed and your program dies.
This type of argument is either 1 or 0. If it is initialized to 1, then it will flip-flop to 0 if the arg is given.
The 'x' as in XOR boolean. Only one of these booleans can be true. The flip-flop behavior also applies to these also. So you may initialize them however, but if one is set then the others are set to the opposite value of the one that is set.
This type takes on the value of the next argument presented.
Example:
my $noodle : Argument(value) = 'egg';
The variable $noodle will be 'egg', unless the argument sequence:
--noodle instant
Where $noodle will then be 'instant'.
This would allow arguments matching a pattern such as:
my @words : Argument(regex) = qr{\A \w+ \z}xms; my @numbers : Argument(regex) = qr{\A \d+ \z}xms;
The permitted argument sequence:
program.pl 12345 4321 horse
This would allow:
my @words : Argument(value);
Where the permitted argument sequence would be:
program.pl --words horse cow pig
Don't put comments at the end of an Argument line.
Example:
my $a :Argument = 1; # comment
This will result in an 'Invalid SCALAR attribute' compile time error.
Version 0.06 intends to resolve the line numbering bug.
Dylan Doxey <dylan.doxey@gmail.com>
Copyright (C) 2009 by Dylan Doxey
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.0 or, at your option, any later version of Perl 5 you may have available.
| Filter::Arguments - Configure and read your command line arguments from @ARGV. |