in reply to Seeking help with split!
... split only by every 6 time the delimiting factor occur. [emphasis added]
>perl -wMstrict -le "my $data = '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 @ra = split m{ (?: , [^,]+){5} \K , }xms, $data; ;; printf qq{'$_' } for @ra; " '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'
Or, alternatively (didn't read this far before posting the first solution), ...
... split only after 5 comas. ... output should be ... like ... "A,B,C,D,E" "F,G,H,I,J" & so on [emphasis added]
>perl -wMstrict -le "my $data = '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 @ra = split m{ (?: , [^,]+){4} \K , }xms, $data; ;; printf qq{'$_' } for @ra; " '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'
\K is available with Perl version 5.10+. See discussion of \K in Look-Around Assertions (sub-section on "(?<=pattern)" "\K") in perlre.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Seeking help with split!
by Anonymous Monk on Jul 01, 2013 at 05:43 UTC | |
by Happy-the-monk (Canon) on Jul 01, 2013 at 07:45 UTC |