Hi Folks,

I've written a little mytest.pl using Getopt::Std:

<script>
#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Std;

getopt('hl');
our ($opt_h, $opt_l);

my $hostname = $opt_h ? $opt_h : undef;
my $file         = $opt_l ? $opt_l : undef;
my @volgroups   = @ARGV;


print "hostname = $hostname\n";
print "file = $file\n";
print "volgroups = ", join("\t", @volgroups), "\n";

</script>

When I run this, I get the following output:

$ ./mytest.pl -h localhost -l file foo bar            
hostname = localhost
file = file
volgroups = foo bar

This is what I expect. If I then add "--volgroups" before the "foo",
I get this:

$ ./mytest.pl -h localhost -l file --volgroups foo bar
hostname = localhost
file = groups
volgroups = foo bar

I would have expected the second output to be the same as the first.
Specifically, I can't see why file now equals "groups".

The man page says that:
"To allow programs to process arguments that look like
 switches, but aren't, both functions will stop processing
 switches when they see the argument "--".  The "--" will
 be removed from @ARGV."

Interestingly enough, if I say --volgroup instead of --volgroups, then
the output says "file = group" instead of "file = groups"!

Can anyone shed some light?
Thanks!

richf





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to