On Sat, Nov 28, 2015 at 09:14:59AM +0100, Aristotle Pagaltzis wrote: > * KES <kes-kes@yandex.ua> [2015-11-27 19:40]: > > When we return list while list is required in this case we will have > > these benefits: > > Just use list assignment in scalar context like you did with the `if`: > > > @x ||= qw/ s o m e d e f a u l t s /; # ('s','o'...'s') if @x is empty > > @x || (@x = qw/ s o m e d e f a u l t s /); > > > @x = $str =~ /^(\d)(\d)(\d)$/ || (); # (7,5,3) if $str eq '753', NOT (3) > > This is nonsensical. Just leave out the `|| ()`. > > (You don’t write `$x = $y // undef;` either, unless you’re hungover.) > > > @x = fn_this() || fn_that(); # faster: only one call to fn_this > > @x = fn_this() ? fn_this() : fn_that() ; # slower: fn_this called twice > > (@x = fn_this()) || (@x = fn_that()); # only one call to fn_this I typically write the latter as: @x = fn_this (); @x = fn_that () unless @x; AbigailThread Previous | Thread Next