in reply to Re: Break an array. I think.
in thread Break an array. I think.

This will destroy the original array! To leave it intact you can do:
@datan = ("1","2","3","4","5","6"); my $i = 0; while ( (my @x = @datan[(0+$i)..(2+$i)]) && $i<$#datan ) { print join(" ",@x), "\n"; $i+=3; } print "l: @datan";


holli, /regexed monk/

Replies are listed 'Best First'.
Re^3: Break an array. I think.
by Roy Johnson (Monsignor) on Nov 22, 2005 at 15:15 UTC
    Or a little more simply,
    for my $i (0 .. $#datan/3) { print join(' ', @datan[$i*3 .. $i*3 + 2]), "\n"; }
    It looks to me like you introduced @x so that splice wouldn't destroy the original array, but then opted not to use splice after all.

    Caution: Contents may have been coded under pressure.