On Mon, 13 Dec 2004 20:23:00 +0100, Jenda Krynicky <[EMAIL PROTECTED]> wrote:
> From: Jay <[EMAIL PROTECTED]>
> > Turn on use strict for starters, and use warnings.  you won't want to
> > run with them, if you have things that you know will cause errors, but
> > they'll give you some other input.  Keep a special eye out for "Bare
> > word found where $x expected" errors.  The thing to remember is that
> > perl has no way of knowing what's really missing.  It just knows what
> > its expects to find based on what it's already seen.  You can change
> > what it expects with coding errors.  My best guess si that you're
> > actually missing a semicolon somewhere.  Consider the following:
> >
> > if (x) {
> >     eval {
> >         print "\n" ;
> >     }
> > }
> >
> > under some combinations of warning, diagnotics, etc., Perl will carp
> > about a missing right brace because it never finds the end of the if
> > block before EOF.  The reason it never finds the end of the if block
> > is that eval needs a semicolon, but the compiler doesn't know why it
> > doesn't find the end of the block, it just knows that it doesn't find
> > the end of that block before EOF.
> 
> You sure? Could you show us a complete example ? And tell us which
> perl did you get this behaviour from?
> 
> Tried all combinations of
>         use strict;
>         use warnings;
>         use diagnostics;
> and never received a word about a missing curly.
> 
> Semicolon is optional before the closing curly brace and it doesn't
> matter what the last command in the block is.
> 

First, you're right, that won't actually produce an error.  I
over-simplified the example, and I was working on the assumption that
the eval was being used to construct something executable.  Consider
the following, which is ugly as all get out, but which I've
encountered in a few different places and versions, mostly people
trying to post-process cgi scripts, particularly greymatter.

#!/usr/bin/perl

use warnings;
use strict;
use diagnostics;

# again simplified, but better
my $two = "]" ;

my $one = '{print "test\n"' ;
$two = '}' if 1 == 0 ;

my $three = $one . $two ;
eval {`perl -e $three`} ;

This produces a runtime (from the main block's perspective) exception
about missing baces, but not in a way that the syntax checker in your
editor would care about, because the brace in question is
single-quoted.

My point, though, was that what the comiler thinks are errors, and
what the programmer thinks are errors are often two different things. 
The most frequent culprit is orgetting a semi-colon, which can
generate several errors depending on the specific context (including,
I believe a missing brace), but never, at least in my experience, the
suggestion that you've forgotten a semicolon.  missing single and
double quotes produce interesting errors, too, as perl quotes
everything up to the next matching quote, and then generates an error
based on what it finds.

I can't tell you how many times every day a semicolon turns out to be
the culprit behind a "bareword found where...", " "'" not found before
EOF...", a "scalar found where operator expected", or a whole host of
other issues, including, I think, complaints about braces.  But then,
as you can probably see from this, when I'm in a hurry I'm not always
the worlds greatest typist.

--jay

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Reply via email to