What"s the best way to test existence of arguments

What"s the best way to test existence of arguments

am 21.01.2008 18:11:33 von pgodfrin

Greetings,

Is there a better way to test for existence of arguments besides
$#ARGV ? I have a little program that uses -s via the getopts module,
and if that option is used I want to force an argument. I suppose I
could use getopts(s:) - but I wondered if there is another "clean" way
to do that?

pg

Re: What"s the best way to test existence of arguments

am 21.01.2008 18:24:30 von Joost Diepenmaat

pgodfrin writes:

> Greetings,
>
> Is there a better way to test for existence of arguments besides
> $#ARGV ? I have a little program that uses -s via the getopts module,
> and if that option is used I want to force an argument. I suppose I
> could use getopts(s:) - but I wondered if there is another "clean" way
> to do that?

GetOpt::Long should give you all the control you'd need, including
default values, types and real named options and readable variable
names. It's a bit more verbose than GetOpt, but IMO it's also more
readable and definitely more flexible.

Joost.

Re: What"s the best way to test existence of arguments

am 21.01.2008 18:32:13 von jurgenex

pgodfrin wrote:
>Is there a better way to test for existence of arguments besides
>$#ARGV ?

What about using @ARGV in scalar context?
if (! @ARGV) {
#I got no command line arguments
}

jue

Re: What"s the best way to test existence of arguments

am 21.01.2008 18:42:30 von pgodfrin

On Jan 21, 11:32 am, Jürgen Exner wrote:
> pgodfrin wrote:
> >Is there a better way to test for existence of arguments besides
> >$#ARGV ?
>
> What about using @ARGV in scalar context?
> if (! @ARGV) {
> #I got no command line arguments
> }
>
> jue

doy - I'm a nitwit...
thanks,
pg

Re: What"s the best way to test existence of arguments

am 21.01.2008 21:32:41 von Ben Morrow

Quoth pgodfrin :
>
> Is there a better way to test for existence of arguments besides
> $#ARGV ?

I would use @ARGV in scalar context rather than $#ARGV, but what's wrong
with that?

@ARGV or die "You need an argument!\n";

seems pretty clear to me.

> I have a little program that uses -s via the getopts module,
> and if that option is used I want to force an argument. I suppose I
> could use getopts(s:)

....or indeed that?

Ben

Re: What"s the best way to test existence of arguments

am 21.01.2008 21:47:21 von Michele Dondi

On Mon, 21 Jan 2008 09:11:33 -0800 (PST), pgodfrin
wrote:

>Is there a better way to test for existence of arguments besides
>$#ARGV ? I have a little program that uses -s via the getopts module,

@ARGV


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^ ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Re: What"s the best way to test existence of arguments

am 22.01.2008 01:02:55 von Ilya Zakharevich

[A complimentary Cc of this posting was sent to
Joost Diepenmaat
], who wrote in article <87d4rvhz1t.fsf@zeekat.nl>:
> GetOpt::Long should give you all the control you'd need, including
> default values, types and real named options and readable variable
> names. It's a bit more verbose than GetOpt, but IMO it's also more
> readable and definitely more flexible.

Do not know as now, but a couple of years ago ::Long had some
limitations which ::Std did not. (I started a rewrite, but did not
finish it.)

Hope this helps,
Ilya