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

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

Thread Previous | Thread Next
January 20, 2018 03:55
Re: [perl #132744] bogus syntax errors with 'use subs'
Message ID:
-----Original Message----- 
From: Zefram
Sent: Saturday, January 20, 2018 12:41 PM
Subject: Re: [perl #132744] bogus syntax errors with 'use subs'

Sisyphus wrote:
>use subs ('FOO');
>if( FOO < 43) { print "a\n" }
>Unterminated <> operator at 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.)


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About