develooper Front page | perl.perl5.porters | Postings from August 2021

Re: "use v5.36.0" should imply ASCII source

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
August 18, 2021 10:39
Subject:
Re: "use v5.36.0" should imply ASCII source
Message ID:
20210818103903.GY11066@etla.org
On Sat, Aug 07, 2021 at 02:01:14PM +0200, Martijn Lievaart wrote:
> Op 07-08-2021 om 08:51 schreef Darren Duncan:

> > If there is a "use utf8;" anywhere in a Perl file, would it not be
> > reasonable to interpret that it is describing the entire file and not
> > just the portion of the file below that statement?
> 
> 
> ... I don't feel that is reasonable. It's not how "use" works in general.
> "Use" affects the file being parsed from that point on. If you want it to
> affect the whole file, put it as the first statement.

It's not just "not reasonable" - it's not possible.

The perl parser can't restart.

Things like reading source code from a pipe (or terminal) could be worked
around (with sufficient buffering), but that's not the fatal problem here.

The problem is that all actions of the parser happen immediately, and
are committed to the symbol table as they are done. So for starters:

    sub foo {
       # I am good
    }

    sub bar {
       1 2 3;
       # I have a syntax error
    }


will generate a definition for &foo before it even starts parsing bar,
and the failure to parse bar won't delete the definition of &foo

So if you wrap the above in an eval (or similar - a require or do in an
eval) and trap the error, you still get &foo.


BEGIN blocks give many many more ways for globally visible side effects to
happen immediately.

So there simply isn't a way to rewind and redo the parse of a file, because
the parsing of a file is not a transaction that ultimately commits or
rolls back - it's kind of AutoCommit, potentially at a
statement-by-statement granularity.

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About