I am at a loss to diagnose a simple syntax error caused by a conspiracy between three perl (5.8.8 on RH-Linux) features.

1) a use constant pragma which performs a division using the / character

2) a comment line with single quote and the / character (changing to double quotes behaves the same way)

3) a switch-case construct

Here is the code example

#!/usr/local/bin/perl -w use strict ; use Switch ; use constant PI => 3.141592653589793 ; use constant HALFPI => ( PI / 2.0 ) ; # half use constant TWOPI => ( 2.0 * PI ) ; # double print TWOPI."\n"; print HALFPI."\n"; # directory is '/home''''''''' my $long = 4.567 ; # radians my $convention = 'W' ; switch ( $convention ) { case ('E') { print "east longitude $long r +adians\n"; } case ('W') { $long = TWOPI-$long ; print "west longitude $long r +adians\n"; } else { print "error: $convention not valid\n"; } };
% monks_help.pl syntax error at monks_help.pl line 11, near ") {" Execution of monks_help.pl aborted due to compilation errors.

Here are the variations that I have found by trial and error that will make the code run to completion:

a) changing the HALFPI line so that NO computations use the / character

use constant HALFPI => ( PI / 2.0 ) ; to use constant HALFPI => { 0.5 * PI } ;

b) changing the TWOPI line so that BOTH computations use the / character

use constant TWOPI => ( 2.0 * PI ) ; to use constant TWOPI => ( PI / 0.5 ) ;

c) removing the / character from the comment line

d) removing all the ' characters from the comment line

e) delete or add ' characters at the end of the comment line so that there are an even number (example has nine)

Obviously I can get this simple pared down example to work by making minor changes, but since use constant and Switch.pm are core parts of Perl 5.8.8 (along with comment capability of course), I would like to learn from what I may have overlooked, assuming for the moment that there is not a bug in the syntax checker.

Thanks in advance for what I am sure will be an interesting (and/or quick) discussion.

BTW, the error does NOT occur on my Windows machine.


In reply to Syntax error with use constant and switch with comment between by ascetic

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.