Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I've a feeling line 6 is redundant. Can get pick the random value without first storing the array reference in line 6 i.e. can lines 6 and 7 be done in a single step? Thanks for reading.1 my %hoa = ( 2 10 => [ "fred", "barney" ], 3 20 => [ "george", "jane", "elroy" ], 4 30 => [ "homer", "marge", "bart" ], 5 ); 6 my $ary = $hoa{$some_number}; 7 return $ary->[rand @$ary];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Get random element from HoA
by FunkyMonk (Bishop) on Dec 27, 2007 at 12:54 UTC | |
by Anonymous Monk on Dec 27, 2007 at 17:19 UTC | |
|
Re: Get random element from HoA
by Fletch (Bishop) on Dec 27, 2007 at 14:00 UTC | |
by Anonymous Monk on Dec 27, 2007 at 18:04 UTC | |
|
Re: Get random element from HoA
by KurtSchwind (Chaplain) on Dec 27, 2007 at 13:07 UTC | |
by Anonymous Monk on Dec 27, 2007 at 18:01 UTC | |
|
Re: Get random element from HoA
by Prof Vince (Friar) on Dec 28, 2007 at 13:52 UTC |