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 ...
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
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... 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 }
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?if ($tmp eq 'F') { (); }elsif ...
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Style or Clarity?
by dragonchild (Archbishop) on Jun 08, 2004 at 20:08 UTC | |
by periapt (Hermit) on Jun 09, 2004 at 12:41 UTC | |
by dragonchild (Archbishop) on Jun 09, 2004 at 13:04 UTC | |
by periapt (Hermit) on Jun 09, 2004 at 19:29 UTC | |
Re: Style or Clarity?
by dave_the_m (Monsignor) on Jun 08, 2004 at 21:34 UTC | |
by periapt (Hermit) on Jun 09, 2004 at 12:44 UTC | |
Re: Style or Clarity?
by Zaxo (Archbishop) on Jun 08, 2004 at 21:52 UTC | |
Re: Style or Clarity?
by sgifford (Prior) on Jun 08, 2004 at 20:29 UTC | |
by Abigail-II (Bishop) on Jun 09, 2004 at 12:24 UTC | |
Re: Style or Clarity?
by Grygonos (Chaplain) on Jun 08, 2004 at 20:28 UTC | |
Re: Style or Clarity?
by CountZero (Bishop) on Jun 08, 2004 at 20:29 UTC | |
Re: Style or Clarity?
by FoxtrotUniform (Prior) on Jun 09, 2004 at 01:54 UTC | |
by periapt (Hermit) on Jun 09, 2004 at 12:48 UTC | |
by exussum0 (Vicar) on Jun 09, 2004 at 19:17 UTC | |
Re: Style or Clarity?
by baruch (Beadle) on Jun 09, 2004 at 03:14 UTC | |
Re: Style or Clarity?
by halley (Prior) on Jun 09, 2004 at 17:40 UTC |
Back to
Seekers of Perl Wisdom