What's the best way to test existence of arguments
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
pgodfrin <pgodfrin [at] gmail.com> 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
pgodfrin <pgodfrin [at] gmail.com> wrote:
>Is there a better way to test for existence of arguments besides
>$#ARGV ?
What about using [at] ARGV in scalar context?
if (! [at] ARGV) {
#I got no command line arguments
}
jue
Re: What's the best way to test existence of arguments
On Jan 21, 11:32 am, Jürgen Exner <jurge... [at] hotmail.com> wrote:
> pgodfrin <pgodf... [at] gmail.com> wrote:
> >Is there a better way to test for existence of arguments besides
> >$#ARGV ?
>
> What about using [at] ARGV in scalar context?
> if (! [at] 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
On Mon, 21 Jan 2008 09:11:33 -0800 (PST), pgodfrin
<pgodfrin [at] gmail.com> 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,
[at] ARGV
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Re: What's the best way to test existence of arguments
Quoth pgodfrin <pgodfrin [at] gmail.com>:
>
> Is there a better way to test for existence of arguments besides
> $#ARGV ?
I would use [at] ARGV in scalar context rather than $#ARGV, but what's wrong
with that?
[at] 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
[A complimentary Cc of this posting was sent to
Joost Diepenmaat
<joost [at] zeekat.nl>], who wrote in article <87d4rvhz1t.fsf [at] 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