Splitting can be done in other ways than using split. Here it is by far easier to describe the pieces that should result from the splitting and use a regex (a simple regex, relatively simple regex):
use strict; use warnings; my $to_split = "'A','B','C','D','E','F','G','H','I','J','K','L','M','N +','O','P','Q','R','S','T','U','V','W','X','Y','Z'"; my @pieces = $to_split =~ /('\w'(?:,'\w'){0,4})/g; $"="\n"; print "@pieces\n";
Or, if you insist on split, use the above as a delimiter, and remove the commas:
use strict; use warnings; my $to_split = "'A','B','C','D','E','F','G','H','I','J','K','L','M','N +','O','P','Q','R','S','T','U','V','W','X','Y','Z'"; my @pieces = grep {$_} split /('\w'(?:,'\w'){0,4}),?/, $to_split; $"="\n"; print "@pieces\n";
In reply to Re: split with a delimiter, every 4 time it occurs.
by hdb
in thread split with a delimiter, every 4 time it occurs.
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |