Hi fellow monks,

I am currently sitting here and am trying to find out what I am doing wrong.

I have an array in which some slices might end with '='. In these cases Id like to join the next slice to the current. I am currently using splice in order to remove slices from my array. For a strange reason I am losing some parts of my array. Can you spot what I am doing wrong?

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @mail = ('Hi i a=','m a cont=','inous &lt;tex=','t&gt; Stop','I ha= +','ve no','idea w=','hats','wrong','grr'); my $i = 0; my $y = 0; while ($mail[$i]) { #print Dumper \@mail, $i; $y = $i + 1; while ($mail[$i] =~ s/=$//) { $mail[$i] .= $mail[$y]; my @tmp = splice (@mail,$y,$y); print Dumper \@tmp; } $mail[$i] =~ s/&lt;/</g; #Some other stuff I need to do $mail[$i] =~ s/&gt;/>/g; $i++; } print Dumper \@mail;
The result should look like this
$VAR1 = [ 'Hi i am a contnous <text> Stop', 'I ha've no', 'idea whats', 'wrong', 'grr' ];
But in fact Ill get:
$VAR1 = [ 'Hi i am a continous <text> Stop', 'I have no', 'hats', 'wrong', 'grr' ];
I would be probably be quicker if I join the array to a big string, remove every '=\n' and exchange my '><' and push everything back into a new array. But I am now stuck with splice as I dont see what my error is.
Hope you can push me into the right direction :)

Thx

Schuk


In reply to splice n dice by Schuk

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.