in reply to splinting a line of text by comma

TMTOWTDI:

$ perl -nE ' chomp; my @x = split /\|/; my ($y) = grep $x[$_] =~ /,/, 0..$#x; for (split /,/, $x[$y]) { splice @x, $y, 1, $_; say join "|", @x; } ' a,b,c|d|e a|d|e b|d|e c|d|e a|b,c,d|e a|b|e a|c|e a|d|e a|b|c,d,e a|b|c a|b|d a|b|e

Although, for dealing with spreadsheet data, Text::CSV would always be my first port of call.

Update: The code I originally posted had:

my @z = split /,/, $x[$y]; for (@z) {

I've reduced that to:

for (split /,/, $x[$y]) {

The output is identical for both cases.

— Ken