Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Getopt::Std problem

Reply
Thread Tools

Getopt::Std problem

 
 
S
Guest
Posts: n/a
 
      02-02-2004
Hi,

I'm using Getopt::Std in a script that I'm writing. While testing
boundary conditions, I notice some strange behavior. Here's the code
snippet in question:

use vars qw /%option/;
getopts('avs:m', \%option) or die Usage();
die "You did not enter any options - run $0 -h to view options\n" if !
%option;

Now, if I run my script with the -s option, but no argument, it dies as
expected, except for the following:


1 at ./make-acct-ctl.pl line 14.

Can anyone help to explain/correct this?
 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      02-02-2004
In article <bvm93c$9mi$>,
S <> wrote:
:I'm using Getopt::Std in a script that I'm writing. While testing
:boundary conditions, I notice some strange behavior. Here's the code
:snippet in question:

:use vars qw /%option/;
:getopts('avs:m', \%option) or die Usage();
:die "You did not enter any options - run $0 -h to view options\n" if !
:%option;

:Now, if I run my script with the -s option, but no argument, it dies as
:expected, except for the following:

:1 at ./make-acct-ctl.pl line 14.

:Can anyone help to explain/correct this?

What exactly does Usage() compute? Is it possible that Usage() is
returning the 1 ? It should return a list, but perhaps along the
way you have an accidental scalar context that is converting a
list containing a single string into scalar(@thatlist) which
would be 1 ?

--
"There are three kinds of lies: lies, damn lies, and statistics."
-- not Twain, perhaps Disraeli, first quoted by Leonard Courtney
 
Reply With Quote
 
 
 
 
S
Guest
Posts: n/a
 
      02-02-2004
Walter Roberson wrote:
> In article <bvm93c$9mi$>,
> S <> wrote:
> :I'm using Getopt::Std in a script that I'm writing. While testing
> :boundary conditions, I notice some strange behavior. Here's the code
> :snippet in question:
>
> :use vars qw /%option/;
> :getopts('avs:m', \%option) or die Usage();
> :die "You did not enter any options - run $0 -h to view options\n" if !
> :%option;
>
> :Now, if I run my script with the -s option, but no argument, it dies as
> :expected, except for the following:
>
> :1 at ./make-acct-ctl.pl line 14.
>
> :Can anyone help to explain/correct this?
>
> What exactly does Usage() compute? Is it possible that Usage() is
> returning the 1 ? It should return a list, but perhaps along the
> way you have an accidental scalar context that is converting a
> list containing a single string into scalar(@thatlist) which
> would be 1 ?
>

sub Usage
{
print <<HELP;

$0 -s <server> | -v | -a | -m

HELP
}

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      02-02-2004

S <> wrote:
> Walter Roberson wrote:
> > What exactly does Usage() compute? Is it possible that Usage() is
> > returning the 1 ? It should return a list, but perhaps along the
> > way you have an accidental scalar context that is converting a
> > list containing a single string into scalar(@thatlist) which
> > would be 1 ?
> >

> sub Usage
> {
> print <<HELP;
>
> $0 -s <server> | -v | -a | -m
>
> HELP
> }


Well, there you go then: print() returns 1 if the print succeeds. You
probably meant

return <<HELP;
....

Ben


--
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based
on the strictest morality. [Samuel Butler, paraphrased]
 
Reply With Quote
 
S
Guest
Posts: n/a
 
      02-02-2004
Ben Morrow wrote:
> S <> wrote:
>
>>Walter Roberson wrote:
>>
>>>What exactly does Usage() compute? Is it possible that Usage() is
>>>returning the 1 ? It should return a list, but perhaps along the
>>>way you have an accidental scalar context that is converting a
>>>list containing a single string into scalar(@thatlist) which
>>>would be 1 ?
>>>

>>
>>sub Usage
>>{
>>print <<HELP;
>>
>>$0 -s <server> | -v | -a | -m
>>
>>HELP
>>}

>
>
> Well, there you go then: print() returns 1 if the print succeeds. You
> probably meant
>
> return <<HELP;
> ...
>
> Ben
>
>


you are correct!!! thanks!
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      02-02-2004
>>>>> "S" == S <> writes:

S> sub Usage
S> {
S> print <<HELP;

S> $0 -s <server> | -v | -a | -m

S> HELP
S> }

see my comments in another current thread on how to do a better usage
sub. the usage sub should do the die/exit itself. and it should take an
error string argument. this makes usage calls much cleaner in the main code.

uri

--
Uri Guttman ------ -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
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
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57