in reply to Re: How to divide a line from a text file into 8 digit chunks
in thread How to divide a line from a text file into 8 digit chunks

Hi I tried both unpack and your suggestion,
my @array = split m/(.{8})/, $string;
seems to create a size 11 array with some additional spaces whereas unpack creates a size 6 array. But I am not sure why it does that.

Replies are listed 'Best First'.
Re^3: How to divide a line from a text file into 8 digit chunks
by moritz (Cardinal) on Feb 24, 2009 at 10:31 UTC
    seems to create a size 11 array with some additional spaces

    This is why I added the line with grep after that.

      I agree the  unpack solution is better, but a regex solution without the  split complication or  push-ing would be something like:
      >perl -wMstrict -le "my $s = 'GRID 213736 15235.2 -2606.28596.178'; my @ra = $s =~ m{ .{1,8} }xmsg; print qq{:$_:} for @ra; " :GRID : : 213736 : : : :15235.2 : :-2606.28: :596.178:
      Update: Did not notice balakrishnan's earlier and essentially identical reply before posting this.