On Tue, Dec 26, 2006 at 06:59:42PM -0800, Travis Thornhill wrote:
> 
> 
> Adriano Allora <[EMAIL PROTECTED]> wrote:    hi to all,
> 
> (and a very good new year's eve). someone can tell me why this script 
> doesn't accept the -h flag?:
> 
> #!/usr/bin/perl -w
> 
> use strict;
> use warnings;
> use Getopt::Std;
> 
> getopt('h');
> my $opt_h;
> if($opt_h)
> {
> [code...]
> }
> 
> You need to declare a hash then pass the hash to the getopt() function.
>   This code is an example of something you can do with getopt(). 

Not necessarily.  It can be done with scalars as easily as with hashes
and, in fact, I do it like that quite often.

Try this instead:

  our $opt_h;
  getopt('h);

That satisfies both the strict pragma and the desire to use a scalar
varaible for your command line option.

Question: Is the -h option meant to be for "help"?  If so, you may be
interested to know that Getopt::Std provides a built-in --help option
that can be used instead (or in addition).

-- 
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"A script is what you give the actors.  A program
is what you give the audience." - Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to