in reply to Re^6: how to let sub return hash of 2 sub?
in thread how to let sub return hash of 2 sub?

You could inline new, but you still need name and val.

I don't see the point of changing

return NameValTuple->new( name => $name, val => $val ); { package NameValTuple; sub new { my $class = shift; bless({ @_ }, $class) } sub name { $_[0]->{name} } sub val { $_[0]->{val} } }
to
return bless { name => $name, val => $val }, 'NameValTuple'; { package NameValTuple; sub name { $_[0]->{name} } sub val { $_[0]->{val} } }

It breaks encapsulation for no reason.