in reply to Push,pop, and splice!
use warnings; use strict; my %storage = map { $_ => 1 } qw(knife wand bow); my %inventory = map { $_ => 1 } qw(axe sword shovel); while (1) { print "Which item would you like to deposit?\n"; print "$_\n" for sort keys %inventory; my $choice = lc <STDIN>; chomp $choice; if (exists $inventory{$choice}) { delete $inventory{$choice}; $storage{$choice}++; print qq(You have stored a "$choice".\n); } elsif ($choice eq 'end') { last; } } use Data::Dumper; $Data::Dumper::Sortkeys=1; print Dumper(\%storage); print Dumper(\%inventory);
|
|---|