I am using switch statements in a couple subroutines located in the same script. In the first subroutine I have a few switch statements. Here is one example:
switch ( $time ) { case "30days" { $caption .= "Past 30 Days"; } case "3mons" { $caption .= "Past 3 Months"; } case "1yr" { $caption .= "Past 1 Year"; } case "all" { $caption .= "All Data"; } }
These statements worked fine until I added a second subroutine and duplicated the switch statements verbatim. Now I am receiving the following compiler errors:
Unquoted string "case" may clash with future reserved word at ./genera +te_xml.pl_edit line 615. String found where operator expected at ./generate_xml.pl_edit line 61 +5, near "case "all"" (Do you need to predeclare case?) Unquoted string "case" may clash with future reserved word at ./genera +te_xml.pl_edit line 618. String found where operator expected at ./generate_xml.pl_edit line 61 +8, near "case "regular"" (Do you need to predeclare case?) syntax error at ./generate_xml.pl_edit line 614, near ") {" syntax error at ./generate_xml.pl_edit line 618, near "case "regular""
These are all referencing a switch statement in the second subroutine. I have scoured my code and cannot find any syntax errors that would cause these errors. (I especially looked around line 614, but there is nothing different. It has been copied verbatim from the first subroutine.) I have included use Switch;. Any suggestions?

In reply to Switch - "case" may clash with future reserved word by ahoffmann

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.