in reply to Passing a hash plus some strings to a subroutine

It's just moaning about your use of individually shifting the args. This passes perlcritic --stern for me:

sub generate { my ($record, $status, %data) = @_; return; }

🦛

Replies are listed 'Best First'.
Re^2: Passing a hash plus some strings to a subroutine
by ikegami (Patriarch) on Dec 17, 2025 at 15:35 UTC

    Nothing wrong with shifting. Easier to provide defaults and comments. And then there's the newish signature feature. Take perlcritic's critiques with a grain a salt, and adjust them to your liking.

Re^2: Passing a hash plus some strings to a subroutine
by LanX (Saint) on Dec 17, 2025 at 15:55 UTC
    Not the same thing tho.

    The OP is passing a hashref, but you are un- and repacking a hash as list of keys and values.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

Re^2: Passing a hash plus some strings to a subroutine
by Anonymous Monk on Jan 10, 2026 at 02:51 UTC
    Why does perlcritic complain about this:
    my %arg = @_;
    Always unpack @_ first...

      It does not complain about that. Here is my SSCCE showing as such:

      $ cat x.pl #!/usr/bin/env perl use strict; use warnings; use utf8; sub foo { my %arg = @_; print "Woo!\n"; return; } foo (z => 3); $ perlcritic --stern x.pl x.pl source OK $

      This suggests that the cause of its complaint (if any) is in the code which you have not shown, such as if you have done something in the sub before that line and hence that line is not "first".


      🦛

        > you have done something in the sub before that line and hence that line is not "first"

        Thank you hippo! That is exactly the case. Why is that not a PBP? I have good reasons for putting code before dealing with parameters in subs, like using IPC::Cmd to check if we can run an executable:

        sub something { return 'oops' unless can_run('something'); my %arg = @_; ... }