Mike Singleton wrote:
> This is a snippet I have a question about. Is this Unix specific...and
> if it is, si there a Win32 equivalent?
>
> use GetOpt::Std;
> ......( other code here)...
> getopts('hn:p:o:s:') or die "$HELP";
> ($Getopt::Std::opt_h) and die $HELP;
No, Get should work under Win32 just fine. Make sure the O is lower case
in Getopt::Std .
Here's a simple alternative that I often use for my quick scripts that
puts all the flags in %A:
use strict;
our %A;
BEGIN { # get command line switches
for (my $ii = 0; $ii < @ARGV; ) {
last if $ARGV[$ii] =~ /^--$/;
if ($ARGV[$ii] =~ /^-{1,2}(.*)$/) {
splice @ARGV, $ii, 1; # remove arg
my $tmp = $1;
if ($tmp =~ /^([\w]+)=(.*)$/) {
$main::A{$1} = $2;
} else {
$main::A{$1}++;
}
} else {
$ii++;
}
}
}
Then your commandline can be like:
perl myscript.pl -d -file=filename.ext -g="abc def.ext"
and %A will have:
$A{d} = 1
$A{file} = 'filename.ext';
$A{g} = 'abd def.ext';
--
,-/- __ _ _ $Bill Luebkert ICQ=162126130
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs