On Fri, 29 Jun 2001, M.W. Koskamp wrote:
> > my $option = @ARGV ? shift : ;
>
> Above option only works for 1 parameter tho (and commandline arguments).
> For function calls i like to use 'named parameters' by accepting a hash of
> options.
Well, yeah, but the topic *was* command-line arguments
> > my $option = defined $ARGV[0] ? $ARGV[0] : "default";
>
> Didn't we already go through all of this a few hours ago? Randal (of
> course) came up with the most succint solution:
>
> my $option = @ARGV ? shift : ;
>
Sorry for trying to be helpful.
Mailing list arent represented in threads in ou
On Fri, 29 Jun 2001, M.W. Koskamp wrote:
> > > my $option = $ARGV[0] || 1;
> >
> > And what if $ARGV[0] equal to 0 ? Ops ..
> >
> > Remember what evaluates to FALSE :
> > * "0"
> > * 0
> > * empty string
> > * undef
>
> my $option = defined $ARGV[0] ? $ARGV[0] : "default";
Didn't we already go t
- Original Message -
From: Evgeny Goldin (aka Genie) <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: Brett W. McCoy <[EMAIL PROTECTED]>
Sent: Friday, June 29, 2001 11:34 PM
Subject: Re: Optional Variables
>
> > my $option = $ARGV[0] || 1;
>
> And
> my $option = $ARGV[0] || 1;
And what if $ARGV[0] equal to 0 ? Ops ..
Remember what evaluates to FALSE :
* "0"
* 0
* empty string
* undef
> "Chas" == Chas Owens <[EMAIL PROTECTED]> writes:
Chas> In cases where you expect 0 to be a valid value it may be better to use
Chas> this construct:
Chas> $var = defined($ARGV[0]) ? $ARGV[0] : DEFAULT;
I prefer the sensible:
$var = @ARGV ? shift : DEFAULT;
Why test defined when you know
On 29 Jun 2001, Chas Owens wrote:
> In cases where you expect 0 to be a valid value it may be better to use
> this construct:
>
> $var = defined($ARGV[0]) ? $ARGV[0] : DEFAULT;
Thanks for pointing that out. That is a more robust way of doing that.
-- Brett
ht
On 29 Jun 2001 09:26:55 -0400, Kim Green wrote:
> What's the proper syntax to indicate that a variable is optional? The script
> that I have created works great when I pass in a variable, but the script
> need to execute the SQL even if I don't pass in a variable.
>
> Thanks,
> Kim
>
>
you migh
On Fri, 29 Jun 2001, Kim Green wrote:
> What's the proper syntax to indicate that a variable is optional? The script
> that I have created works great when I pass in a variable, but the script
> need to execute the SQL even if I don't pass in a variable.
You can set a sane default for the variab
If your variable is sometimes undefined then you can replace it with a
default.
$variable_to_pass = $variable || "Default";
print "$variable_to_pass\n";
$variable = "Now this is set";
$variable_to_pass = $variable || "Default";
print "$variable_to_pass\n";
-Original Message-
From: Kim
> My question pertains to using command line variables in Perl.
> I created a script that uses SQL and runs from an application, and the
only
> parameter is optional. This script works well when the parameter is
> required or not used at all.
> I have altered the SQL script so that it can accept
11 matches
Mail list logo