develooper Front page | perl.perl5.porters | Postings from February 2019

[perl #133850] "Scalar found where operator expected" on printing toindirect filehandle within s///e

Thread Previous
From:
Tony Cook via RT
Date:
February 19, 2019 04:44
Subject:
[perl #133850] "Scalar found where operator expected" on printing toindirect filehandle within s///e
Message ID:
rt-4.0.24-16322-1550551466-918.133850-15-0@perl.org
On Fri, 15 Feb 2019 11:37:16 -0800, corion@corion.net wrote:
> last week I (together with E. Choroba) stumbled on a weird syntax
> error (Windows shell quoting):
> 
> perl -wle "s/(.*)/print $fh $1/e"
> 
> This surprisingly gives a syntax error, yet still seems to run the
> code:
> 
> Scalar found where operator expected at -e line 1, near "$fh $1"
>         (Missing operator before $1?)

This isn't a syntax error, but a warning (but still buggy).

The code inside the replacement part of s///e is handled with a sublex, and the code that decides whether an operator or term is expected after C<print $fh> is mostly skipped for a sublex.

The attached fixes that, doing the same checks for C<print $fh> in a sublex within brackets as for a normal parse.

This fixes the same problem for C<< "... ${code} ..." >>.

Tony

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=133850

Thread Previous


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