Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting Implicit use of @_ in subroutine entry with signatured subroutine is experimental

Tags:

perl

Why does this code generate the warning message:

sub really()
{
    &{$reallys{$reallyParent->PathName =~ s/.*\.//r}};
}

The warning message is to advise that @_ may be unavailable in future versions of perl within a subroutine using signatures. But this subroutine does not use @_. I change the declaration to:

sub really :prototype()

which has the same effect in this case, and of course the code works fine.

like image 782
Steve Waring Avatar asked Dec 22 '25 22:12

Steve Waring


1 Answers

You have the signatures feature enabled (e.g. using use v5.36;), and the sub has a signature (()).

The sub makes a &foo-style call. That syntax is a sub call without localization and modification of @_. The called sub not only receives the caller sub's arguments, but it does so because they share the same @_.

So you are using @_ in a sub with a signature.

It sounds like the Perl developers are unsure if @_ will continue to be available in subs with a signature, so it's warning that your code may break in the future.

You can avoid the warning and potential future problems by using a normal sub call (i.e. one that avoids sharing @_).

&{ $reallys{ $reallyParent->PathName =~ s/.*\.//r } }();

or

$reallys{ $reallyParent->PathName =~ s/.*\.//r }->();
like image 121
ikegami Avatar answered Dec 26 '25 01:12

ikegami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!