Scott R. Godin wrote at Thu, 06 Jun 2002 07:09:18 +0200:
> thanks for the pointers. always good to get some feedback, but one of them, I think,
>is not right:
>
>> > my $savefile = File::Spec->catfile(
>> > File::Spec->curdir(),
>> > defined($opts{'f'}) ? $opts{'f'} : 'ModuleCheck.txt'
>>
>> $opts{f} ||= 'ModuleCheck.txt';
>
> this will work in this context?
In general it replaces $opts{f} with the default value if $opts{f} is a false value.
Of course, if $opts{f} would be "0" or 0 or "" or something similar it would be
replaced by
'ModuleCheck.txt', too.
I assumed that $opts{f} stands for a filename where such false values doesn't make
really sense. So
I suggested to use the standard idiom fo handling default values.
Of course, there a special cases where you have to use something like
$a = defined $a ? $a : 'default';
but in your case I think it isn't such a case.
> Am I dreaming or should I go test this?
Always test.
(www.extremeprogramming.org)
Cheerio,
Janek