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

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

Thread Previous
From:
Sawyer X
Date:
January 20, 2018 20:33
Subject:
Re: [perl #132744] bogus syntax errors with 'use subs'
Message ID:
7dc63e4f-2b11-1c7c-91cc-26ebf93a16e6@gmail.com


On 01/20/2018 04:54 AM, sisyphus1@optusnet.com.au wrote:
> -----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.)

Relevant to this is the following Perl::Critic policy:

https://metacpan.org/pod/Perl::Critic::Policy::ValuesAndExpressions::ConstantBeforeLt

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