> Since I want to treat -book like a boolean

The problem is that you are telling Getopt::Long that "book" expects a
string value:

> "book=s" =>\$book,

This is untested, but this should work.

> "book" =>\$book,

It sets the value of $book to 1 if the option is present.

See the Getopt::Long docs, the section on Simple Options.
http://search.cpan.org/author/JV/Getopt-Long-2.34/lib/Getopt/Long.pm#Simple_
options

Rob


-----Original Message-----
From: Trina Espinoza [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 23, 2003 9:11 PM
To: [EMAIL PROTECTED]
Subject: GetOpts: boolean and argument value combos


Hey Perl Peps,

I am stuck in the mudd and hoping someone can give me a few clues that will
help get me back on track.

I want to submit some arguments like so:
./script1.pl -book  -title HP3 -chapter 04 

 NOTE: -book does not have an argument
Now I have been using GetOpt::Long and everything works except the first
value -book. Since I want to treat -book like a boolean, I do
not give it value, which causes problems because I guess it needs to receive
some sort of value in it's current format. This is causing problems
where the value of the second argument -title does not show. Is there a
syntactical form I can follow to treat -book like a boolean and feed the
other arguments
values? Can I continue to use Getopt::Long?

Any suggestions would be much appreciated.

CODE
-----------------------------------
use Getopt::Long;
use File::Path;
#use strict;


GetOptions  (    
                "book=s" =>\$book,
                "magazine=s" =>\$magazine,
                "video=s" =>\$video,
                "c=s" => \$chapter,
                "t=s" => \$title,
                 );

##Routes to appropriate subroutine
print "SHOW TEST: $sPath\n";
if ($book) {
    itemCreator($chapter, $title);
}    
###SUBROUTINES
sub showCreator {
        my($chapter, $title) = @_;
        print "\n"; 
        print "CHAPTER: $chapter\n";  ###Not appearing because -book did not
receive an arguement :(
        print "TITLE: $title: $template\n";
       
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to