Schuk has asked for the wisdom of the Perl Monks concerning the following question:
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?
The result should look like this#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @mail = ('Hi i a=','m a cont=','inous <tex=','t> 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/</</g; #Some other stuff I need to do $mail[$i] =~ s/>/>/g; $i++; } print Dumper \@mail;
But in fact Ill get:$VAR1 = [ 'Hi i am a contnous <text> Stop', 'I ha've no', 'idea whats', '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.$VAR1 = [ 'Hi i am a continous <text> Stop', 'I have no', 'hats', 'wrong', 'grr' ];
Thx
Schuk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: splice n dice
by Paladin (Vicar) on Mar 09, 2006 at 18:12 UTC | |
|
Re: splice n dice
by ivancho (Hermit) on Mar 09, 2006 at 18:14 UTC | |
by Schuk (Pilgrim) on Mar 09, 2006 at 18:18 UTC |