Re: Optional Variables

2001-06-29 Thread Brett W. McCoy
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

Re: Optional Variables

2001-06-29 Thread M.W. Koskamp
> > 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

Re: Optional Variables

2001-06-29 Thread Brett W. McCoy
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

Re: Optional Variables

2001-06-29 Thread M.W. Koskamp
- 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

Re: Optional Variables

2001-06-29 Thread Evgeny Goldin (aka Genie)
> my $option = $ARGV[0] || 1; And what if $ARGV[0] equal to 0 ? Ops .. Remember what evaluates to FALSE : * "0" * 0 * empty string * undef

Re: Optional Variables

2001-06-29 Thread Randal L. Schwartz
> "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

Re: Optional Variables

2001-06-29 Thread Brett W. McCoy
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

Re: Optional Variables

2001-06-29 Thread Chas Owens
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

Re: Optional Variables

2001-06-29 Thread Brett W. McCoy
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

RE: Optional Variables

2001-06-29 Thread John Edwards
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

Re: Optional Variables

2001-06-28 Thread Me
> 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