Use split function in perl

Hello,

if i have file like this:
010000890306932455804 05306977653873 0520080417010520ISMS SMT ZZZZZZZZZZZZZOC30693599000 30971360000 ZZZZZZZZZZZZZZZZZZZZ202011302942311 010000890306946317387 05306977313623 0520080417010520ISMS SMT ZZZZZZZZZZZZZOC306942190000 30971360000 ZZZZZZZZZZZZZZZZZZZZ202010300391748 010000890306945153336 05306977918990 0520080417010521ISMS SMT ZZZZZZZZZZZZZOC306942190000 30971360000 ZZZZZZZZZZZZZZZZZZZZ202011304607230 010000890306948068406 05306977404213 0520080417010523ISMS SMT ZZZZZZZZZZZZZOC306942190000 30971360000 ZZZZZZZZZZZZZZZZZZZZ202010000717971 010000890306998573372

How can i perform a split based on the number of characters or base on the "size? For example split every 70 characters.
Foa example i want in array[0] to be stored the 70 first characters of the file and in array[1] the next 70 charactets etc...

How can i do this?

Try this:

@splitstrings = ($string =~ /.{1,70}/g);

The intention is to do a greedy match on every occurance of 70 characters (or less, to match any extra trailing characters) and return the list of matches.

or using split:

@data = split(/.{1,70}/,$string);
@data=split (/.{70}/,$string);

Actually I don't think either one of our suggestions will work. The split() function leaves out the delimiter by default, in this case there is no delimiter. If you put parenthesis around the delimiter it might work:

@data = split(/(.{1,70})/);

But that seems awkward at best and may not work correctly.

KevinADC is correct: you can capture the delimiter in split in the just way he describes, and this gives you your chunks of 70 characters, but of course you also capture the stuff in between the delimiters (because that's what split is for!), and that gives you a bunch of empty array elements too.