Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Getopt::Long , handles the number zero differently..
Using the example code below, I find that I can
use getopt handily to pass all sorts of
variables to my script, as long as a
value passed is not a 0 (zero)

How to I use getopt::long and be able to
pass the number zero as a value?
Code, and  behavior follows

Thanks! Mike D
.....................
MYTEST
#!/usr/local/bin/perl
use Getopt::Long;
GetOptions("o"=>\$oflag,
"string=s"=>\$stringmandatory,
"int=i"=> \$mandatoryinteger,
print "oflag $oflag\n" if $oflag;
print "stringmandatory $stringmandatory\n" if
$stringmandatory;
print "mandatoryinteger $mandatoryinteger\n" if
$mandatoryinteger;

print "Unprocessed by Getopt::Long\n" if $ARGV[0];
foreach (@ARGV) {
print "$_\n";
}
................................
# ./MYTEST -stringmandatory=1
Unknown option: stringmandatory
# ./MYTEST --stringmandatory=1
Unknown option: stringmandatory
# ./MYTEST --string
Option string requires an argument
# ./MYTEST --string
Option string requires an argument
# ./MYTEST --string=abc
stringmandatory abc
# ./MYTEST --string=1
stringmandatory 1
# ./MYTEST --string=0
# ./MYTEST --int=0
# ./MYTEST --int=1
mandatoryinteger 1


 ________________________________________
__________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Report this thread to moderator Post Follow-up to this message
Old Post
Mike Donnelly
12-22-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:06 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.