in reply to Re: syntax error with constant
in thread syntax error with constant

...the parser has an additional clue which it uses to work out the right way to parse the statement...

I think the parser is reallly straightforward in this respect: known -X filetest operators will give the error, unknown ones will give the warning. Nothing to do with upper case of lower case: -a works but gives the warning even though lowercase, whereas -T will give the compile error.

perldoc -f -X lists the following uppercase filetest operators:

 -T  File is an ASCII text file (heuristic guess).
 -B  File is a "binary" file (opposite of -T).

 -M  Script start time minus file modification time, in days.
 -A  Same for access time.
 -C  Same for inode change time (Unix, may differ for other platforms)
so don't call your constants T, B, M, A or C ;-).

Liz

Replies are listed 'Best First'.
Re: Re: Re: syntax error with constant
by TomDLux (Vicar) on Aug 04, 2003 at 01:08 UTC

    But why does it happen with multi-character constant names?

    DB<1> use constant foo => 1 DB<2> print 1-foo Ambiguous use of -foo resolved as -&foo() at (eval 15)[/usr/lib/perl5/ +5.8.0/perl5db.pl:17] line 2. eval '($@, $!, $^E, $,, $/, $\\, $^W) = @saved;package main; $ +^D = $^D | $DB::db_stop; print 1-foo; ;' called at /usr/lib/perl5/5.8.0/perl5db.pl line 17 DB::eval called at /usr/lib/perl5/5.8.0/perl5db.pl line 1323 DB::DB called at -e line 1 0

    Same thing happens with FOO.

    I don't encounter this problem, because I put spaces between terms and operators. Insert invisible 'nyah nyah' here

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

      I think the issue that is resolved has to do with my original assessment:

      What I think happens is that the parser gets confused with trying to handle the:

      -key => value
      notation.

      The warning does not occur when you have "-foo()" because the parentheses indicated a subroutine call. However, without it, "-foo" could still be a key specification. So the parser must take that into account after parsing -foo. Then it hits the ";" and it can resolve the issue. Although in this case strictly speaking, I don't see an ambiguity. So the warning seems superfluous to me.

      I guess a p5per with more perl internals knowledge should speak up ;-)

      Liz

      Huh, that's interesting. I get the same thing if I use quux as a constant, even though -q isn't a filetest operator. And this contradicts the documentation given by perldoc -f -X:
      Note that "-s/a/b/" does not do a negated substitution. Saying "-exp($foo)" still works as expected, however--only single letters following a minus are interpreted as file tests.