Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

In reply to Style or Clarity? by periapt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (7)
    As of 2020-10-29 17:10 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (274 votes). Check out past polls.

      Notices?