in reply to Syntax error with use constant and switch with comment between

Your particular problem occurs with 2.09 but not with 2.14. It was probably 2.13 that fixed it. My earlier advice to avoid Switch remains, though. It can create errors in legit code with no indication that it is the cause, so using it can cost you a lot of time.

  • Comment on Re: Syntax error with use constant and switch with comment between

Replies are listed 'Best First'.
Re^2: Syntax error with use constant and switch with comment between
by ascetic (Novice) on Dec 07, 2009 at 03:52 UTC

    Thanks for looking into the version differences. I will take your advice and avoid Switch. I am proposing (to nonbelievers I work with) to use perl as a replacement for what is currently a custom sub-configuration file with logical selections based on settings in a top-level config file. The switch statement would be more familiar and therefore more likely to be favorably received (than if-elsif-elsif-elsif...else). In any case, I will request a company wide update to 5.10 before I propose the config file change. I trust that the given-when construct is a different animal inside than switch-case.

    I also plan to get Readonly installed to replace use constant as suggested by Conway's PBP book, unless...

    Also, thanks to the other monk who provided background on how Switch is implemented under the covers. I am not a fan of source filters.

      I propose the config file change. I trust that the given-when construct is a different animal inside than switch-case.

      It is a switch statement

      given ($convention) { when ('E') { print "east longitude $long radians\n"; } when ('W') { $long = TWOPI-$long; print "west longitude $long radians\n"; } default { print "error: $convention not valid\n"; } }

      But it doesn't have to do its own Perl parsing like Switch because it's a builtin control statement like for and while.