Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between "$|++" and "$|=1"

Tags:

perl

Can someone please help to clarify? Also, please mention if there are other representation of "$|".

Thanks in advance.

like image 374
Gentle Avatar asked Dec 04 '22 16:12

Gentle


2 Answers

There is no practical difference that I know of; $| only stores a boolean (0 or 1), so incrementing it will never result in any value other than 1. The micro-micro-optimizers might tell you that ++ is faster.

Decrementing it, on the other hand, acts as a toggle, but I can't think of any good reason to do that in production code: either you want it on or off.

like image 64
ysth Avatar answered Dec 13 '22 01:12

ysth


$| is super magical, so that $|++ does the same as $| = 1; But why rely on magic when you can just do what you mean ($| = 1;)?

like image 35
ikegami Avatar answered Dec 13 '22 01:12

ikegami