Um...the goto bit was a joke. (although, it does come in handy for these sort of logic issues)

But your example structure still doesn't behave like switch/case in C (okay, I did more LPC than I've ever done C, and that was all a long time ago). The important thing is that matching 'needs_slight_cleaning' does not mean that it matches 'good_value', or that it will match after &clean_up_values is called.

Because I've been doing without switch for so long, it's difficult to think of examples when these structures are really useful. Once you see the logic, it makes perfect sense, though.

Okay, here's a logic situation -- you have a program that's monitoring servers. You based on a given alert, you need to decide how to escallate.

switch ($machine_name) { # master LDAP server: case 'einstein': &alert_management(); # LDAP replicas case 'joule': case 'boltzman': case 'hawking': &alert_ldap_sysadmin(); # the mail systems. (that authenticate off of LDAP) case 'feynman': case 'faraday'; case 'curie': case 'newton': &alert_mail_sysadmin(); # helpdesk gets notified of everything not development default: &alert_helpdesk(); # development servers: case 'teller': case 'penn': case 'houdini': case 'copperfield': &log(); }

Blah...submitted too early...anyway, the point is, that in that example, if 'einstein' is true, we alert management, ldap sysadmin, mail sysadmin, helpdesk, and it gets logged. (okay, I could've moved '&log' outside of the switch statement). But flow continues until there's a break...and in this case, there's no break. It gets even tricker when you have multiple paths like that through the system. (this was just ldap and mail servers... imagine if I add in web servers, and some of those webservers are also LDAP authenticating... okay, well, at that point, switch might not be so good for that one.... but we could alert the web admins as part of the ldap replica section, and then have a seperate section for the web servers.

I can do this in perl. (either using goto, or by using much more complicated lookup tables to tell how things propogate ... which may be needed, as the rules for notification can't be flattened to one dimension)


In reply to Re^4: Control Structures by jhourcle
in thread Control Structures by artist

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, details, 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, summary, 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.