in reply to Re: Converting File Delimiters
in thread Converting File Delimiters

That is so much nicer than what I came up with, but I'll add mine, too (otherwise it would have felt like a total waste of time):
#!/usr/bin/env perl use strict; use warnings; use feature 'say'; my $string = qq(aaa,bbb,"ccc,ddd",fff,ggg,"hhh,iii",jjj); my @split_on_comma = split /,/, $string; my @quoted; my @ready_to_join; for (@split_on_comma) { if ( /^"/ .. /"$/ ) { s/"//g; #remove this if you actually want "s in your output push @quoted, $_; } else { push @ready_to_join, join ',', @quoted if scalar @quoted; @quoted = (); push @ready_to_join, $_; } } my $pipe_delim = join '|', @ready_to_join; say $pipe_delim;
Output: aaa|bbb|ccc,ddd|fff|ggg|hhh,iii|jjj

Replies are listed 'Best First'.
Re^3: Converting File Delimiters
by mmueller44 (Novice) on Aug 09, 2012 at 23:37 UTC

    This code is what I want, but how do I get it to use a file for input and output?

    I have tried various revisions but not having any luck

    Thanks, Mike