http://qs321.pair.com?node_id=362525

periapt has asked for the wisdom of the Perl Monks concerning the following question:

I sometimes find that, in the course of processing decisions, I write a construct similar to this ...
... doing something ... $tmp = "some result"; # not an actual value if($tmp eq 'F'){ ; # do nothing, spot held for clarity }elsif($tmp =~ /[MICL]/){ ... # do something ... }else{ ... # do something }
I know there are ways to eliminate the first comparison but I rather find the structure to be clearer. Still, I got to wondering about the NOOP code in the first if. Does Perl even have a NOOP code when it compiles? B::Deparse reported this construct as an empty list
if ($tmp eq 'F') { (); }elsif ...
OK, so is an empty list placed at this point in the bytecode so that when reached, the program evaluates the list? In what context? Or is this just a shorthand display for some NOOP code? Or am I missing some point entirely?

Thanks

Update: Thanks for the great information. Early in my Perl life, I benchmarked this construct a few times to satisfy myself that speed wasn't an issue. In all the instances that I tested, the construct using the NOOP was at least as fast as the original construct so I tend to opt for clarity.

I like the return if ... option although I still get twinges about having multiple exits from a subroutine. Just can't get that structured BASIC out of my soul ;o)

Thanks again.

PJ
We are drowning in information and starving for knowledge - Rutherford D. Rogers
What good is knowledge if you have to pull teeth to get it - anonymous