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

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

Thread Previous | Thread Next
From:
sisyphus1
Date:
January 25, 2018 01:43
Subject:
Re: [perl #132732] use if - behaviour does not match documentation
Message ID:
88E3100800C44B4EA6A16E96469EBC0A@OwnerPC311012


-----Original Message----- 
From: James E Keenan via RT
Sent: Thursday, January 25, 2018 8:18 AM
To: OtherRecipients of perl Ticket #132732:
Cc: perl5-porters@perl.org
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, 
FUNCTIONS;')

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

As an example, 'no if' seems to work fine with warnings.pm:

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

Outputs:

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

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 strict.pm, 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";
is_regexp(1);
print "DONE\n";

simply outputs "DONE" instead of throwing an error.

Is the difference that (wrt re.pm), 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 strict.pm function that we 
explicitly call ??

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