So, undef before I return or check it for definedness before I fill it?
Update: I emptied the two keys before I returned, and it seems to work.
sub random { my ($user_input, $list) = @_; $list->{'all'} = [ map { @$_ } values %{$list} ]; $list->{'keys'} = [ grep {$_ !~ /(?:all|keys)/} keys %{$list} ]; my $random_thing; if ($user_input && $user_input =~ /(?:help|options)/) { $random_thing = 'Your options are: '.join(', ',sort @{$$list{'keys +'}}).', or all.'; } elsif ($user_input && $user_input =~ /dump/) { use Data::Dumper; $random_thing = Dumper($list); } else { my $input = $user_input ? $user_input : 'all'; my @random_list = shuffle(@{$$list{$input}}); $random_thing = $random_list[rand @random_list]; } $list->{'all'} = []; $list->{'keys'} = []; return $random_thing; }
In reply to Re^2: I have a list expanding when I don't want it to
by Lady_Aleena
in thread I have a list expanding when I don't want it to
by Lady_Aleena
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |