http://www.perlmonks.org?node_id=1041767


in reply to split with a delimiter, every 4 time it occurs.

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";

Replies are listed 'Best First'.
Re^2: split with a delimiter, every 4 time it occurs.
by Anonymous Monk on Jul 01, 2013 at 08:19 UTC
    I want this ','(not just comma) as the delimiter. I tried changein the coma to ',' but not working!