As suggested by Anonymonk, warnings show that using your @indexes unaltered means you are trying to access a element off the end of @arr.

johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' my @arr = qw{ zero one two three four }; my @idx = ( 0 .. $#arr ); my $one = splice @arr, 1, 1; say $one; say join q{ }, @arr; say join q{ }, @idx; say join q{ }, @arr[ @idx ]; pop @idx; say join q{ }, @idx; say join q{ }, @arr[ @idx ];' one zero two three four 0 1 2 3 4 Use of uninitialized value in join or string at -e line 8. zero two three four 0 1 2 3 zero two three four

I hope this is helpful.

Update: Expanded example with more descriptive output.

johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' my @arr = qw{ zero one two three four }; say qq{\@arr before splice : @arr}; my @idx = ( 0 .. $#arr ); say qq{Original \@idx : @idx}; my $one = splice @arr, 1, 1; say qq{\$one from splice : $one}; say qq{\@arr after splice : @arr}; say qq{\@arr bad slice : @arr[ @idx ]}; my @newidx = ( 0 .. $#arr ); say qq{New \@newidx : @newidx}; say qq{\@arr good slice : @arr[ @newidx ]};' @arr before splice : zero one two three four Original @idx : 0 1 2 3 4 $one from splice : one @arr after splice : zero two three four Use of uninitialized value in join or string at -e line 9. @arr bad slice : zero two three four New @newidx : 0 1 2 3 @arr good slice : zero two three four

Cheers,

JohnGG


In reply to Re: splice and indexes by johngg
in thread splice and indexes by teun-arno

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.