Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Help using Getopt::Mixed

Reply
Thread Tools

Help using Getopt::Mixed

 
 
Stan Brown
Guest
Posts: n/a
 
      11-02-2003
I'm trying to add a usage message to a script that uses Getopt::Mixed. I
want to print this message whenever a bad commnad line option is passed to
the script. I' using the module like this:

use Getopt::Mixed "nextOption" ;


Getopt::Mixed::init('F i e f=s d:i debug:i configfile=s');
my $badOption = \&print_usage;
while (($option, $value, $pretty) = nextOption()) {
if(( $option eq 'f') || ( $option eq 'configfile' ))

I just added the "print_usage" line, based upon my reading of the perldoc
page on this module, but it's not calling the print_usage() function
(which is defiend earlier in the script, when I pass it an undefined
argument (-Z for instance).

Instead, I get the following generic error mesage:

webcam.pl: unrecognized option `-Z'

What am I doing wrong here?

--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
 
Reply With Quote
 
 
 
 
James Willmore
Guest
Posts: n/a
 
      11-02-2003
On Sun, 2 Nov 2003 14:07:53 +0000 (UTC)
Stan Brown <(E-Mail Removed)> wrote:
> I'm trying to add a usage message to a script that uses
> Getopt::Mixed. I want to print this message whenever a bad commnad
> line option is passed to the script. I' using the module like this:
>
> use Getopt::Mixed "nextOption" ;
>
>
> Getopt::Mixed::init('F i e f=s d:i debug:i configfile=s');
> my $badOption = \&print_usage;
> while (($option, $value, $pretty) = nextOption()) {
> if(( $option eq 'f') || ( $option eq 'configfile' ))
>
> I just added the "print_usage" line, based upon my reading of the
> perldoc page on this module, but it's not calling the print_usage()
> function(which is defiend earlier in the script, when I pass it an
> undefined argument (-Z for instance).
>
> Instead, I get the following generic error mesage:
>
> webcam.pl: unrecognized option `-Z'


Try:

--worked for me, but my not for you--
#!/usr/bin/perl -w

use strict;
use warnings;
use diagnostics;

sub print_usage{
print "Usage .....\n";
print "Bad option was: $_[1]\n";
#you _need_ the 'exit' here, or you'll get an infinite loop
exit;
}

use Getopt::Mixed qw(nextOption) ;

Getopt::Mixed::init('F i e f=s d:i debug:i configfile=s');
$Getopt::Mixed::badOption = \&print_usage;
while (my($option, $value) = nextOption()) {
if(( $option eq 'f') || ( $option eq 'configfile' )){
print "if stuff here ...\n";
}
}
Getopt::Mixed::cleanup();
----end---

I'm thinking the author left out the part about needing the
'$Getopt::Mixed' from the begining of 'badOption'. 'badOption' is a
reference to a subroutine that's used in the module. In order to set
this reference, you need to define where the reference points to
(which you tried) _ and_ what it's namespace is (which you didn't do,
but the author did not make clear - the 'Getopt::Mixed' portion).

Plsu, I don't think you need the $pretty" in the exampl you gave. I'm
not even sure _where_ you got that from. There's no refereence to it
in the documentation that I found. But, to be fair, I'd only read
what I needed to read

I know what I'm trying to say, but not sure if I'm saying it
correctly. Bottom line - it worked for me and I'm thinking it'll work
for you

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Mark's Dental-Chair Discovery: Dentists are incapable of asking
questions that require a simple yes or no answer.
 
Reply With Quote
 
 
 
 
Stan Brown
Guest
Posts: n/a
 
      11-02-2003
In <(E-Mail Removed) .net> James Willmore <(E-Mail Removed)> writes:

>On Sun, 2 Nov 2003 14:07:53 +0000 (UTC)
>Stan Brown <(E-Mail Removed)> wrote:
>> I'm trying to add a usage message to a script that uses
>> Getopt::Mixed. I want to print this message whenever a bad commnad
>> line option is passed to the script. I' using the module like this:
>>
>> use Getopt::Mixed "nextOption" ;
>>
>>
>> Getopt::Mixed::init('F i e f=s d:i debug:i configfile=s');
>> my $badOption = \&print_usage;
>> while (($option, $value, $pretty) = nextOption()) {
>> if(( $option eq 'f') || ( $option eq 'configfile' ))
>>
>> I just added the "print_usage" line, based upon my reading of the
>> perldoc page on this module, but it's not calling the print_usage()
>> function(which is defiend earlier in the script, when I pass it an
>> undefined argument (-Z for instance).
>>
>> Instead, I get the following generic error mesage:
>>
>> webcam.pl: unrecognized option `-Z'


Thanks, that was exactly what I had wrong. Now it works.

Thanks, again.
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why doesn't this "belongs_to" line of code, using options override,not work??? (need help using belongs_to with options) Greg Hauptmann Ruby 1 10-30-2008 10:44 PM
Help Help Help Pentax S5i Help needed (Please) The Martian Digital Photography 14 06-20-2008 07:56 AM
Help! Cannot login using IE but can using FF hplayer03 ASP .Net 3 08-17-2007 03:33 PM
HELP!!HELP!! - Import XMl into SQl using ASp Michael Persaud ASP .Net Building Controls 3 08-17-2004 06:09 PM
HELP! HELP! HELP! Opening Web Application Project Error =?Utf-8?B?dHJlbGxvdzQyMg==?= ASP .Net 0 02-20-2004 05:16 PM



Advertisments