develooper Front page | perl.perl5.porters | Postings from August 2021

Re: PSC #034 2021-08-20 - "Namespaces Special"

Thread Previous | Thread Next
From:
Yuki Kimoto
Date:
August 31, 2021 00:44
Subject:
Re: PSC #034 2021-08-20 - "Namespaces Special"
Message ID:
CAExogxMJ0YH4nGxuH3JLjistQfWSwqYp285JAJc=rkn7MRCEgA@mail.gmail.com
2021-8-30 17:16 Renée Bäcker <p5p.list@perl-services.de> wrote:

> Am 30.08.21 um 10:01 schrieb Yuki Kimoto:
> >
> > Is this really?
> >
> >   perl -E 'sub substr { print "substr\n" }; substr();'
> >
> > Output
> >
> >   Not enough arguments for substr at -e line 1, near "substr()"
> >   Execution of -e aborted due to compilation errors.
> >
> > Imported symbols don't seem to override CORE::substr,
> >
> > Although the following is OK.
> >
> >   perl -E 'sub substr { print "substr\n" }; &substr();'
> >
> > Output
> >
> >   substr
> >
>
> $ cat test_import.pl
> #!/usr/bin/perl
>
> use v5.20;
>
> use strict;
> use warnings;
>
> use lib '.';
> use MYImport;
>
> substr();
>
> $ cat MYImport.pm
> package MYImport;
>
> use parent 'Exporter';
>
> our @EXPORT = qw(substr);
>
> sub substr {
>     print "substr\n";
> }
>
> 1;
>
> $ perl test_import.pl
> substr
>
>
Renée, Eirik

Thank you.

I have understood that subroutine import and sub declaration in the current
package are different.

feature doesn't break imported subroutines, on the other hand, breaks sub
declaration.

  perl -e 'use strict;use warnings;use feature "say"; sub say { print "ppp"
} say("aaa")'

Output

  aaa

1. It has no effect on the CPAN libraries or user libraries.
2. It affects the user script, so it needs to be rewritten a little in
lexical scope.

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