in reply to Break an array. I think.

@datan = ("1","2","3","4","5","6"); while ( my @x = splice(@datan, 0, 3) ) { print join(" ",@x), "\n"; }
Boris

Replies are listed 'Best First'.
Re^2: Break an array. I think.
by holli (Abbot) on Nov 22, 2005 at 09:48 UTC
    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/
      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.