Good day everyone!
I am trying to practice push and pop so I was making this little project similar to an NPC that stores your items.
The snippet probably looks like something that doesn't exist or make sense because I'm still learning so I apologize and I accept all responses even if they are suppose to offend me.So here is a snippet, will post problem afterwards!
my @storage = qw(knife wand bow); my @inventory = qw( axe sword shovel ); sub depo { sleep (1); print "Which item would you like to deposit?\n", "1. Nevermind\n"; foreach my $inv (map(ucfirst, @inventory)){ print "$num. $inv\n"; $num++; } $choice = lc(<STDIN>); chomp $choice; if ($choice =~ $item) { my $item = splice @inventory, $choice; push(@storage,$item); print "You have stored a \"$item\".\n"; }
SO what I am trying to do is that if I put in "Axe" from my @inventory and it exist, it will take the "axe" from @inventory and add it to @storage so then @storage will equals to knife wand bow axe while @inventory will equals to only sword and shovel.
And if it doesn't exist, it will do
else { print "Please input a valid answer!\n"; sleep (1); &bank; }
Thank you for your time :D!
P.S. there was a grep function before the if($choice =~$item).. thats why the $item was there if you were wondering.. I was experimenting :D!In reply to Push,pop, and splice! by Jabox
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |