Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Awwww man, i like that ... thing:
|| : ||
gave me an Atari flashback! :D

I do commend runrig for giving a working piece of code that kicked the dog doo out of it's conterpart. It took me very little time to parse it, but i am not a newbie anymore.

For a newbie - that's just got to look like a nightmare. I really think that this is why Ovid loves nested if-else blocks:

Because newbies (especially those that are new to Perl but not to programming!) can understand them must faster.

Me, i like the dispatch table - once you really start using them, it's hard not to. Point of little return, so to speak. For one thing, it is very scalable - adding two new conditions was very easy:

my $func = ($foo > 7) ? $bar && \&bar_mysub || $baz && \&baz_mysub || $qux && \&qux_mysub : $bar && \&bar_other_mysub || $baz && \&baz_other_mysub || $qux && \&qux_other_mysub ; $func->($foo) if $func;
I did move the '?' and the ';' to make it easier to cut-copy and paste it ... but, man have we gotten away from a simple solution:

Tuck the check for the value of $foo away in the subroutines themselves, redundant, but that should be a piece of cake to follow and seems more configurable in the long run as well as very straight foward. The redundant pieces will end up becoming different anyway, thanks to Murphy's Law. ;)

jeffa

|| : ||

In reply to (jeffa) 5Re: (Ovid - Why I love nested If-Else blocks) by jeffa
in thread Why I Hate Nested If-Else blocks by jeffa

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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 musing on the Monastery: (16)
    As of 2014-09-23 14:29 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (223 votes), past polls