in reply to Re^3: I have a list expanding when I don't want it to
in thread I have a list expanding when I don't want it to

poj, I did it your way (with my own additions) by not creating two new hash keys.

use List::Util qw(shuffle); sub random { my ($user_input, $list) = @_; my $random_thing; if ($user_input && $user_input =~ /(?:help|options)/) { my $keys = join(', ', keys %{$list}); $random_thing = "Your options are: $keys, or all."; } elsif ($user_input && $user_input eq 'list') { $random_thing = $list; } else { my @random_list; # The following gets the keys to randomize instead of $list->{'key +s'}. if ($user_input && $user_input eq 'keys') { @random_list = keys %{$list}; } # The following gets the entire list to randomize instead of $list +->{'all'}. elsif (!$user_input || $user_input eq 'all' ) { @random_list = map { @$_ } values %{$list}; } else { @random_list = shuffle(@{$$list{$user_input}}); } $random_thing = $random_list[rand @random_list]; } return $random_thing; }
No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena