Well, that's what I get for posting before the Mt. Dew has kicked in -- I completely missed what the closure was doing. (and of course, I didn't actually run it).

But well, that being said, there are cases where switch is useful. Yes, it can be done through work arounds, but if you're going to do this sort of thing often enough, it's annoying to have to do extra work when other languages have it built in, and you know that the one part you're dealing may be easier to implement in some other language.

I know there are modules, and plenty of different ways to handle switch-like syntax in Perl, possibly because your dispatch tables would be tuned differently depending on your exact needs. Sometimes, I just want something to work, no matter how inefficiently, for those times when my time is more valuable than the execution time of the program --

I don't want to research which module best fits my needs, and doesn't have known issues, then go and download the module through CPAN, only to find that it has some other dependancy (that I'm going to need to install on whatever other machines I may try to run this script on, etc.). Modules may be great, but there's always the assumption that something has been more thoroughly tested if it's packaged with the main distribution, or if it's a builtin function, and it's going to be less of a headache to maintain in a multiple system environment.


In reply to Re^6: 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.