Split on Split overlap [ RAKU ]

You are splitting the result of the first split, which is a list; the split method will coerce whatever it's called on to a string and then splits it. A list will stringify (via its Str method) to its members separated by single spaces. That is the reason why some of the resulting fields have two L and C pairs and a space in between.

This will get you the result you want:

say "L1:C1\tL1:C2\tL1:C3\nL2:C1\tL2:C2\tL2:C3\nL3:C1\tL3:C2\tL3:C3"
    .split("\n")
    .map( *.split( "\t" ).Slip )

Since it splits the result of splitting the first, and then converts it into a Slip to get it slipped into the wider array.


If you would like your split to give you the individual pieces as one list, rather than a list of lists, you can use the split method's variant that takes a list of delimiters to split by:

say "L1:C1,L1:C2;L1:C3\nL2:C1-L2:C2|L2:C3^L3:C1".split([",", ";", "\n", "|", "^"]).raku;
# output: ("L1:C1", "L1:C2", "L1:C3", "L2:C1-L2:C2", "L2:C3", "L3:C1").Seq

Passing the :k or :v adverbs to the split method call will leave the separator in the result list as separate entries; with :k the value will be the index in the separators list that has the matched separator in it, with :v the separator itself will be in the result list.

Tags:

Split

Raku