If you wanted a random element from a random array (which I think is what you're aiming at):
return do { my $arry = $hoa{ (keys %hoa)[rand %hoa] }; $arr->[ rand @$ +arry ] };
Or possibly:
return $hoa{ my $key = (keys %hoa)[ rand %hoa ] }->[ rand @{$hoa{$key} +} ];
I can't think of a clean way to do it without some temporary or building a parallel data structure (containing either the indexes or a copy of all the elements).
The cake is a lie.
The cake is a lie.
The cake is a lie.
In reply to Re: Get random element from HoA
by Fletch
in thread Get random element from HoA
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |