What is the meaning of the operator || =

In Perl, what is the value of the ||= operator in the following example?

 $sheet -> {MaxCol} ||= $sheet -> {MinCol}; 
+6
source share
2 answers

a ||= b is similar to a = a || b a = a || b , therefore:

 $sheet->{MaxCol} ||= $sheet->{MinCol}; 

looks like:

 $sheet->{MaxCol} = $sheet->{MaxCol} || $sheet->{MinCol}; 

Regarding ikegami, commentary differs in that a ||= b; evaluates only a once and evaluates a to b . It matters when a is magic or not a scalar.

+7
source
 $sheet -> {MaxCol} ||= $sheet -> {MinCol}; 

have the same effect as

 if (!$sheet->{MaxCol}) { $sheet->{MaxCol} = $sheet->{MinCol}; } 

or

 $sheet->{MaxCol} = $sheet->{MinCol} unless $sheet->{MaxCol}; 
+5
source

Source: https://habr.com/ru/post/946347/


All Articles