The "default" action is not to do a assignement at all. But using the current value of $foo will do it as JavaFan suggested:
$foo = $bar // $foo;However this is not much better then
$foo = $bar if defined $bar;Because the other part of the statement ($foo) is duplicated - if I have a long variable like $myhash{mykey}->{mykey2} instead of $foo it only gets uglier. I was looking for a simple and short syntax like:
$foo =// $barBut appereantly such operator does not exist in Perl. The best solution I found so far (also ugly but not getting more complex if $foo and $bar are long expressions) is:
{local $_ = $bar; $foo = $_ if defined $_;}
In reply to Re^2: Assignment to a value only if it is defined
by voj
in thread Assignment to a value only if it is defined
by voj
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |