I've a file containing tab separated values - most, but not all are
quoted - and now I'm wondering how to substitute a non-quoted value like
<tab>20090807<tab> by sth. like <tab>"20090807"<tab>
You would have to do some complicated regex (possibly multiple regx's),
but that depends on the data sample in regards to quote's, newlines, or other
shapes it can have.
A simple way is to split on tab, fix up the value, the join it back together.
Its ugly though.
-sln
------------
use strict;
use warnings;
my @ar = (
qq{\n12345145\t\n36367\t"qfqqbv"\n\t"0987"\t"asdf"a"\n },
qq{\t"01234"\taaaa\t494848\t}
);
for my $str (@ar) {
my $newstring = join "<tab>", map {/^(\s*|)"*(.*?|)"*(\s*|)$/; $1.'"'.$2.'"'.$3 } split (/\t/,$str);
print "-> $newstring\n\n";
}
__END__