Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of operator ||=

Tags:

operators

perl

In Perl, what's the meaning of operator ||= in the following example ?

$sheet -> {MaxCol} ||= $sheet -> {MinCol};
like image 557
user1895140 Avatar asked Jun 02 '13 14:06

user1895140


People also ask

What is the meaning of operator <>?

: one that operates: such as. : one that operates a machine or device. : one that operates a business. : one that performs surgical operations.

What is the meaning of operator number?

In quantum mechanics, for systems where the total number of particles may not be preserved, the number operator is the observable that counts the number of particles. The number operator acts on Fock space. Let.

What is an example of an operator?

In programming, an operator is a symbol that operates on a value or a variable. Operators are symbols that perform operations on variables and values. For example, + is an operator used for addition, while - is an operator used for subtraction.

What is the full form of operators?

The full form of OPR is Operator/Operate/Operation.

Who is an operator of a company?

Definition: A Business Operator is the primary force driving a team working towards fulfillment of a company vision. This may be a dedicated team of contractors, but usually includes a mixture of contractors and employees.

What does operator mean in slang?

US, Slang. a clever, persuasive person who generally manages to achieve his or her ends.

What is operator in a sentence?

Operator: An auxiliary that performs a grammatical operation. The first auxiliary in a verb phrase is an operator. In short, this is the auxiliary that “does the work” in the verb phrase! Examples: You have been smoking >>> have is the operator here.

What do you mean by corporators?

: a corporation organizer, member, or stockholder.


2 Answers

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

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

is similar to:

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

Per ikegami's comment, the difference is that a ||= b; only evaluates a once, and it evaluates a before b. This matters when a is magical or isn't a scalar.

like image 83
Andomar Avatar answered Sep 20 '22 22:09

Andomar


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

have same effect as

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

or

$sheet->{MaxCol} = $sheet->{MinCol} unless $sheet->{MaxCol};
like image 36
mpapec Avatar answered Sep 18 '22 22:09

mpapec