# Limit the region where the variable @pack is visible { my(@pack); sub new_pack { my(@sorted_pack); foreach my $suit ("S","H","D","C") { foreach $val (0..10,"J","Q","K","A") { push(@sorted_pack,$val.$suit); } } # This way of shuffling a pack is untested, # inefficient and probably flawed @pack = (); while($#sorted_pack > 0) { my($idx); $idx = rand $#sorted_pack; push(@pack,splice(@sorted_pack,$idx,1)); } } sub next_card { new_pack() if(!@pack); return pop(@pack); } } # NB: None of this code is tested