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

I only tought there is a "short" construct, which can solve this request.

Moose and Moo were already suggested to you as examples of frameworks to make writing classes easier.

  • Comment on Re^5: how to let sub return hash of 2 sub?

Replies are listed 'Best First'.
Re^6: how to let sub return hash of 2 sub?
by ikegami (Patriarch) on May 30, 2015 at 16:00 UTC
    I wasn't aware that they could create anonymous classes, and I'm not seeing the advantage of
    { package NameValTuple; use Moose; has name => ( is => 'rw' ); has val => ( is => 'rw' ); no Moose; __PACKAGE__->meta->make_immutable; }
    over
    { package NameValTuple; sub new { my $class = shift; bless({ @_ }, $class) } sub name { $_[0]->{name} } sub val { $_[0]->{val} } }

      Fair point; if the OP only needs to write a couple of classes by hand that's fine. If he ends up needing to write more classes than that, perhaps some with inheritance etc., learning and using one of the Perl OO frameworks should show its advantages pretty quickly.