perl

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


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.


Solution

  • 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 }->();