in reply to Re: Converting File Delimiters
in thread Converting File Delimiters
Output: aaa|bbb|ccc,ddd|fff|ggg|hhh,iii|jjj#!/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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Converting File Delimiters
by mmueller44 (Novice) on Aug 09, 2012 at 23:37 UTC |