Firstly, I agree with toolic above, that hashes are likely to be much better for what you are trying to do.

Second, have a look at splice for the splice syntax. Rather than using the name of the item you want to splice, you should provide the index, and number of items. Something like this:

#!/usr/bin/perl use warnings; use strict; depo(); sub depo { my @storage = qw(knife wand bow); my @inventory = qw(axe sword shovel); my $num = 1; my $choice; my $item; sleep (1); print "Which item would you like to deposit?\n", "$num. Nevermind\n"; foreach my $inv (map(ucfirst, @inventory)){ $num++; print "$num. $inv\n"; } $choice = lc(<STDIN>); chomp $choice; my $index = 'N'; for (my $x = 0; $x <= $#inventory; $x+= 1) { if ($inventory[$x] eq "$choice") { $index = $x; $item = $inventory[$x]; } } if ($index eq 'N') { print "$choice is not available.\n\n"; return; } $item = splice (@inventory, $index, 1); push(@storage,$item); print "You have stored a \"$item\".\n\n"; print STDERR "STORAGE: @storage\nINVENTORY: @inventory\n\n"; }

I hope that helps a little.


In reply to Re: Push,pop, and splice! by mtmcc
in thread 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.