can I do $value = shift ||= "Default value"
?

On Tue, Jul 22, 2008 at 9:36 AM, Robert Boone <[EMAIL PROTECTED]> wrote:
>
> The short cut for if(!defined $value); is a perl 5.10/6 feature:
>     $value //= "some sorta default";
>
> The other is good in all perl 5 version and lower, I think:
>    $value = "some sorta default" if(!$value);
>    becomes
>    $value ||= "some sorta default";
>
>
> On Jul 22, 2008, at 9:31 AM, Todd Rinaldo wrote:
>
>> ok so someone explain these operators, cause obviously I shoulda read
>> the whole camel book!
>>
>> Here is what I've always had to do the hard way. what's the simpler?
>>
>> I often do this
>> sub foo {
>>  my $value = shift;
>>  $value = "some sorta default" if(!defined $value);
>>
>> }
>>
>> Of course sometimes I want to do the permutation:
>>
>> sub bar {
>>  my $value = shift;
>>  $value = "some sorta default" if(!$value);
>>
>> }
>>
>> is there a simpler way?
>> _______________________________________________
>> Houston mailing list
>> [email protected]
>> http://mail.pm.org/mailman/listinfo/houston
>> Website: http://houston.pm.org/
>
>
> _______________________________________________
> Houston mailing list
> [email protected]
> http://mail.pm.org/mailman/listinfo/houston
> Website: http://houston.pm.org/
>



-- 
Todd Rinaldo
[EMAIL PROTECTED]
_______________________________________________
Houston mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/houston
Website: http://houston.pm.org/

Reply via email to