in reply to regex pattern match

Unless you have reason to split the first n-1 pieces as well, you only need the last one separated.

Once you have it, you replace the commata with quote, newline, appropriate number of spaces, quote

Voila!

while(<DATA>) { chomp; my ($first, $last ) = /(.+",)(.+)/; print $first; $first = " " x length( $first ); $last =~ s/,/"\n$first"/g; print "$last\n"; } __DATA__ "A","B","C","D" "A","B","C","D,E,F" "A","B","C","D" "A","B","C","D,R,T"

Replies are listed 'Best First'.
Re^2: regex pattern match
by McA (Priest) on Mar 29, 2013 at 10:15 UTC

    Nice approach.

      I do not like the line where I replace $first with spaces. It really should be:

      $first =~ s/./ /g;

      I love regular expressions! However, things can get easily out of hand and become unmaintainable. Also, these are quite format dependent. Should there be only one column, it would not work anymore.