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

"1" => \&get_ifc_name({'ifc_default' => 'test_me',}),

To fix the problem but lose arguments:

"1" => \&get_ifc_name,

I'm too tired to read all your code, but it seems to me, what you need a classic from functional programming¹:

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

OUTPUT

$VAR1 = { 'one' => 1, 'two' => 2 };

Cheers Rolf

FOOTNOTES:

(1) IIRC it's called "currying".

Replies are listed 'Best First'.
Re^2: Subroutine references inside of a hash with arguments.
by LanX (Saint) on Jul 24, 2009 at 23:25 UTC
    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