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

Re: [perl #132732] use if - behaviour does not match documentation

Thread Previous | Thread Next
January 25, 2018 01:43
Re: [perl #132732] use if - behaviour does not match documentation
Message ID:

-----Original Message----- 
From: James E Keenan via RT
Sent: Thursday, January 25, 2018 8:18 AM
To: OtherRecipients of perl Ticket #132732:
Subject: [perl #132732] use if - behaviour does not match documentation

> Is anyone familiar with where/how 'no' is implemented in the source code?

I'm thinking 3 distinct cases:

1) You want to load a module unconditionally ('use MODULE;')

2) You want to load a module conditionally ('use if CONDITION, MODULE, 

3) Having loaded a module, you then wish to conditionally remove specific 
piece of that module's functionality ('no if CONDITION, MODULE, 

As an example, 'no if' seems to work fine with

### 1 ###
use warnings;
no if 0, warnings => "numeric";
print "$]\n";
print "hello world" + 1, "\n";
print "\$z: $z\n";


Name "main::z" used only once: possible typo at line 5.
Argument "hello world" isn't numeric in addition (+) at line 4.
Use of uninitialized value $z in concatenation (.) or string at line 

If we change the condition to 'no if 1', then the output is the same, except 
that the numeric warning has disappeared.
And that's as to be expected.

Similarly, with, the following works fine, outputting "DONE":

use strict;
no if 1, strict => "subs";
use if 1, Math::BigInt => 1;
print "DONE\n";

That would blow up at compile time if strict "subs" was enabled - which is 
exactly what happens if the condition is changed to  'no if 0'.

But the same doesn't happen with re, as James has discovered.

use re;
no if 1, re => "is_regexp";
print "DONE\n";

simply outputs "DONE" instead of throwing an error.

Is the difference that (wrt, we're actually explicitly calling a 
function - whereas, with warnings, "numeric" is not a function that we 
explicitly call, just as "subs" is not a function that we 
explicitly call ??


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