Getopt::Std , option with no argument

H

hymie!

Greetings.

I've run across this issue:

#!/usr/bin/perl
use Getopt::Std;
getopt('l');
print "$opt_l\n";

eric@db01:~/last_update$ ./test.pl -l5
5
eric@db01:~/last_update$ ./test.pl -l larry
larry
eric@db01:~/last_update$ ./test.pl -l

eric@db01:~/last_update$

perldoc tells me:
For each
switch found, sets $opt_x (where x is the switch name) to
the value of the argument, or 1 if no argument.

However, that doesn't seem to be happening. $opt_l is not being set to
1 when there is no argument.

Is this my fault?

Thanks.

hymie! http://www.smart.net/~hymowitz hymie_@_lactose.homelinux.net
===============================================================================
He's neurotic, which is Jewish for "intense." --Cybill
===============================================================================
 
H

hymie!

In our last episode, the evil Dr. Lacto had captured our hero,
hymie_@_lactose.homelinux.net (hymie!), who said:
Greetings.

I don't know if my "cancel" will work or not, but about 5 minutes after
I posted, I found this:

http://groups.google.com/group/perl...read/thread/5a705619506b39c5/36198c4d3ecc0ed7

which contains this crucial paragraph:

Not all options handled by getopt() are expected to have a value. With
getopt('xy'), -x and -y expect an argument, and all other options do not
expect an argument. perl foo -x -y -z will set $opt_x to '-y' and $opt_z
to 1.

and solved my problem.

hymie! http://www.smart.net/~hymowitz (e-mail address removed)
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top