in reply to Re: Embedded Newlines or Converting One-Liner to Loop
in thread Embedded Newlines or Converting One-Liner to Loop
Thanks Rolf!
I believe I was able to make your idea work. I've posted a solution below, feel free to critique if you have the notion.
my $wait_for_odd_quotes = 0; my $line_accumulator = ''; while(<$CSVFILE>) { chomp(my $this_line = $_); my @matches = $this_line =~ /(\")/g; my $count = @matches; if($wait_for_odd_quotes == 0){ if($count % 2 == 1){ $line_accumulator = $this_line; #Reset Accumulator $wait_for_odd_quotes = 1; #Prime next loop to look for end + of quotes } else { print $OUTFILE $this_line . "\n"; #We are not looking for +and end quote and this line doesn't have an odd number of quotes so w +e'll write it to file } } else { if($count % 2 == 1){ $line_accumulator .= $this_line; #matched our open quotes, + taking this last bit $wait_for_odd_quotes = 0; #reset so next loop knows we're +not looking to close print $OUTFILE $line_accumulator . "\n"; } else { $line_accumulator .= ' ' . $this_line; } } } print $OUTFILE $line_accumulator . "\n"; #catch final line if it had e +mbedded newlines
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Embedded Newlines or Converting One-Liner to Loop
by Marshall (Canon) on Dec 15, 2016 at 08:45 UTC | |
by LanX (Saint) on Dec 15, 2016 at 11:09 UTC | |
by Marshall (Canon) on Dec 15, 2016 at 13:30 UTC | |
by LanX (Saint) on Dec 15, 2016 at 14:32 UTC | |
|
Re^3: Embedded Newlines or Converting One-Liner to Loop
by perldigious (Priest) on Dec 15, 2016 at 14:40 UTC |