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

[perl #131671] `use subs 'xx';` should be identical to `sub xx;`

From:
James E Keenan via RT
Date:
December 6, 2018 20:51
Subject:
[perl #131671] `use subs 'xx';` should be identical to `sub xx;`
Message ID:
rt-4.0.24-17597-1544129461-376.131671-15-0@perl.org
On Wed, 28 Jun 2017 18:00:43 GMT, the.rob.dixon@gmail.com wrote:
> This is a bug report for perl from the.rob.dixon@gmail.com,
> generated with the help of perlbug 1.40 running under perl 5.24.0.
> 
> 
> -----------------------------------------------------------------
> 
> The documentation for `subs` doesn't suggest anything beyond
> pre-declaration of the named subroutines. But that is what
> `sub x` is supposed to do.
> 
> `use subs` is a pair with `use vars`, and I think both should be
> deprecated, but that is a different problem.
> 
> This program
> 
> sub unlink;
> unlink 'path';
> 
> produces
> 
> Ambiguous call resolved as CORE::unlink()
> 
> whereas
> 
> use subs 'unlink';
> unlink 'path';
> 
> gives
> 
> Undefined subroutine &main::unlink called
> 
> I believe that the second behaviour is correct, and the
> first code example should produce the same result.
> 
> 

When running the first program (attached as 131671-a-subs.pl), I don't get the result you report.  Instead, the program runs and exits silently.

#####
$ cat 131671-a-subs.pl 
sub unlink;
unlink 'path';
$ perl 131671-a-subs.pl 
$ 
#####

Your second program:

#####
$ cat 131671-subs.pl 
use subs 'unlink';
unlink 'path';
$ perl 131671-subs.pl 
Undefined subroutine &main::unlink called at 131671-subs.pl line 2.
#####

Thank you very much.

-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=131671



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About