[Mastering-perl] tweak to "Configuring Perl Scripts"
Leslie Peters
les.peters at gmail.com
Wed Jun 28 13:14:03 EDT 2006
Brian:
Under "Command line switches", include 'perl -s' for the sixth list item:
#!/usr/bin/perl -s
print "-i = $i\n";
print "-t = $t\n";
print "--debug = ${-debug}\n";
print "first argument = $ARGV[0]\n";
C:\WINDOWS\system32\cmd.exe /c perl -s "\Documents and Settings\lpeters\My
Documents\perl\Mastering Perl\config_ex_1.pl" -i -t --debug --
--this_is_an_argument
-i = 1
-t = 1
--debug = 1
first argument = --this_is_an_argument
As I burrowed further, I found that with some code, you can parse the
%main:: symbol table to find the variables
created when -foo and -bar are used, and create new table entries in
%main::, as if you had used -f -o -o and -b -a -r:
for my $key (keys %{\%main::}) {
if ($key =~ m/^(?!std)[-a-z]+$/) {
map { ${$_} ||= $$key; } split(//, $key);
}
}
# assume "perl -s script.pl -bar=1 -baz=2
print $b, $a, $r, "\n";
print $b, $a, $z, "\n";
C:\WINDOWS\system32\cmd.exe /c perl -s "\Documents and Settings\lpeters\My
Documents\perl\Mastering Perl\config_ex_1.pl" -bar=1 -baz=2
111
112
In the event that two word-arguments contain the same character (-bar=1
-baz=2), the first one wins.
If -bar and -baz were replaced by --bar and --baz, the last one wins.
C:\WINDOWS\system32\cmd.exe /c perl -s "\Documents and Settings\lpeters\My
Documents\perl\Mastering Perl\config_ex_1.pl" --bar=1 --baz=2
221
222
Hit any key to close this window...
Les
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://five.pairlist.net/pipermail/mastering-perl/attachments/20060628/486c1f10/attachment.htm
More information about the Mastering-perl
mailing list