Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: How to divide a line from a text file into 8 digit chunks

by ozgurp (Beadle)
on Feb 24, 2009 at 09:40 UTC ( #745948=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://745948]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2022-05-24 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?