in reply to how to let sub return hash of 2 sub?
That line will work if you return a list of objects.
Say you want to create an object for each element of a hash, where name is the key of the element, and val is the value of the element.
If you instead returned a list of hashes, it would look likesub parameter { ... return map { NameValTuple->new( name => $_, val => $rv{$_} } keys(% +rv); }
print $_->{name}, ': ', $_->{val}, "\n" for $objA->parameter( 'a.x' );
To return a list of hashes, you'd use
sub parameter { ... return map { +{ name => $_, val => $rv{$_} } } keys(%rv); }
(The "+" might not be needed. You can remove it if you don't get an error without it.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to let sub return hash of 2 sub?
by toohoo (Beadle) on May 27, 2015 at 15:12 UTC | |
by ikegami (Patriarch) on May 27, 2015 at 20:48 UTC | |
by toohoo (Beadle) on May 28, 2015 at 12:59 UTC | |
by ikegami (Patriarch) on May 28, 2015 at 14:00 UTC | |
by jdporter (Paladin) on May 28, 2015 at 14:12 UTC | |
| |
by toohoo (Beadle) on Jun 01, 2015 at 12:26 UTC | |
by Anonymous Monk on May 28, 2015 at 14:12 UTC | |
by ikegami (Patriarch) on May 30, 2015 at 16:00 UTC | |
| |
by Anonymous Monk on May 27, 2015 at 15:35 UTC |