http://www.perlmonks.org?node_id=1004868


in reply to Re^2: new way to code html?
in thread new way to code html?

use of the ternary for simple conditionals is a handy trick to have up your sleeve.

I'd worry about having a grasp of the language (context, syntax) before worrying about micro-optimizations

-MO=Deparse,-p says

use Benchmark (':all'); my($foo, $bar); cmpthese((-1), {'ternary', sub { ((int(rand(2)) ? ($foo = 1) : $bar) = 1); } , 'if_else', sub { if (int(rand(2))) { ($foo = 1); } else { ($bar = 1); } } });

More clearly  ((int(rand(2)) ? ($foo = 1) : $bar) = 1);

is

( ( int(rand(2)) ? ($foo = 1) : $bar ) = 1 );
which is an error