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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.