The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Sub::Params - Handle function arguments


   use Sub::Params qw[ named_or_positional_arguments ];

   sub foo {
      my ($self, @args) = @_;
          my %args = named_or_positional_arguments(
         args => \@args,
         names => [qw[ foo bar baz]],

   # following calls are equivalent in behavior
   foo( 1, 2, 3 );
   foo( foo => 1, bar => 2, baz => 3 );
   foo( { foo => 1, bar => 2, baz => 3 });


Module contains functions helping dealing with parameters.

named_or_positional_arguments( args => [], names => [] )

Helps coversion from positional to named arguments.

Use it only for minimal transition period, it is not intended for permanent usage.

Takes reference to actual function arguments and names in order of positional interface.



Reference to argument array


Positional argument names in form used in named arguments call

Function recognizes named arguments when:

every odd parameter is name from names list
first and only argument is hashref with keys from names list

Uses Hash::Util::lock_keys to detect valid names.


Thanks GoodData for supporting open-source contribution


This module comes with no warranty and is distributed as is.

To participate please use discussions using project's github issues.



This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at: