in reply to Re: Suggestions to make this code more Perlish
in thread Suggestions to make this code more Perlish
That's a good solution but it has a couple of rough edges.
I don't think the first line needs to be treated separately. You could remove these four lines:
my $first_line = <DATA>; chomp $first_line; $first_line =~ s/,/chr(31)/eg; print $first_line, chr(30);
Your join is joining the fields and the record separator. Just add parentheses to
print join chr(31), @fields, chr(30);
like this
print join(chr(31), @fields), chr(30);
That way, the field separators will just separate the fields. :-)
You're also not adequately handling a quoted field at the start of a record or two quoted fields adjacent to each other. Here's two examples from your output (I think these are the only ones):
... "Bonaire, Sint Eustatius and Saba|"Charissa, Lana, Liberty, Quail|4451 +7|18| ... "Virgin Islands, British|"Otto, Macon, Caldwell, Sasha|87676|49| ...
Here's the matching lines from the input:
... "Bonaire, Sint Eustatius and Saba","Charissa, Lana, Liberty, Quail",44 +517,18 ... "Virgin Islands, British","Otto, Macon, Caldwell, Sasha",87676,49 ...
-- Ken
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Suggestions to make this code more Perlish
by Laurent_R (Canon) on Mar 30, 2014 at 10:06 UTC | |
by kcott (Archbishop) on Mar 30, 2014 at 13:24 UTC |