in reply to Re: Subroutine references inside of a hash with arguments.
in thread Subroutine references inside of a hash with arguments.

Just noticed your passing hashes as refs and not as lists, so better do that:

use strict; use Data::Dumper; sub get_ifc_name { my ($hash)=@_; print Dumper $hash; } sub setdefaults { my ($func,$defs)=@_; return sub { my ($hash)=@_; $func->({%$defs,%$hash}) } } my $f2= setdefaults( \&get_ifc_name, {one =>1}); $f2->({two =>2}); __DATA__ #OUTPUT $VAR1 = { 'one' => 1, 'two' => 2 };

The two hashes will be flattened and reference of the joined hashes will be passed to your sub.

Please note, that the defaults can be overridden by keys of the same name. (I think this is anyway the idea of defaults :-)

Cheers Rolf