develooper Front page | perl.perl5.porters | Postings from January 2018

Re: [perl #132744] bogus syntax errors with 'use subs'

Thread Previous | Thread Next
From:
sisyphus1
Date:
January 20, 2018 03:55
Subject:
Re: [perl #132744] bogus syntax errors with 'use subs'
Message ID:
A199EDA6C9EF425C85B56B3C60199AB3@OwnerPC311012
-----Original Message----- 
From: Zefram
Sent: Saturday, January 20, 2018 12:41 PM
To: perl5-porters@perl.org
Subject: Re: [perl #132744] bogus syntax errors with 'use subs'

Sisyphus wrote:
>use subs ('FOO');
>
>if( FOO < 43) { print "a\n" }
...
>Unterminated <> operator at subs.pl line 5.

> This isn't a bug, but an intentional grammatical feature.  Using explicit 
> parens to delimit the empty argument list is one solution, as you've 
> found.  The other solution is to give the sub an empty prototype, which 
> alters its grammatical role such that the ambiguous characters will be
interpreted as infix operators:
>
> $ perl -lwe 'sub FOO () { return 42; } if (FOO < 43) { print "a"; } print 
> FOO + 1'
> a
> 43

I hadn't thought of that solution - and it's a very useful one because, 
unlike my workarounds, it's something that I can use to solve the actual 
issue I have.

However, I think the subs documentation should at least acknowledge this 
issue, and also mention that solution. (I don't think it needs to be a 
detailed coverage.)

Currently the documentation simply states that use subs " will predeclare 
all the subroutine whose names are in the list, allowing you to use them 
without parentheses even before they're declared".
And my demos (which meet the requirements of that documentation) clearly 
show it's not always as simple as that.

(I just noticed a small typo in that section of the docs that I quoted - 
"subroutine" should be plural, not singular.)

Cheers,
Rob 

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