Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am using various switches in my script. I have the Getopts::std
module and I wrote the following line:
   getopts('F:S:D:T:I:plen', \%OPTS);

How can I see if the switch, such as -F, was followed by an argument?
What I mean is that if in the prompt I write:
  ./ -F
How can I stop the script and check if -F was actually followed by an
argument and what that argument is?

Re: Getopts::std

lnatz wrote:
Quoted text here. Click to load it

This is the second time you've posted a message about a non-existing
module.  I can only *assume* you meant the module Getopt::Std, and its
getopts() function.  Spelling and capitalization both count. Please put
some care into your posts.

Quoted text here. Click to load it

This is such an absurdly easy thing to check, I have to ask why you
didn't.  I've never used this module in my life, but it took me all of
5 minutes to find it on CPAN (including account for your misspellings),
read the documenation enough to see this:

"For those of you who don't like additional global variables being
created, getopt() and getopts() will also accept a hash reference as an
optional second argument. Hash keys will be x (where x is the switch
name) with key values the value of the argument or 1 if no argument is

and then run a small test case to verify:

$ perl -MData::Dumper -MGetopt::Std -e'getopts(q, \%opts); pri
nt Dumper \%opts' -- -o -f
$VAR1 = {
          'f' => undef,
          'o' => 1

It seems that options which take a value but are not provided a value
get the undefined value.  Why didn't you put this much effort into your
own post?

Paul Lalli

Site Timeline