Mary Mary - 4 months ago 16
Perl Question

remove non-ascii characters and append a space in the field where the non-ascii characters were using a Perl all remove the double "quote"?

I am passing a fixed (flat file). I need help to remove non-ascii characters and append a space in the field where the non-ascii characters were using a Perl all remove the double "quote"? I also need to remove any non visible characters and leave data:
I need to do this using regex;

Please see example below:

FOìO BAR PO BOX 1234
LASDìBA" PO BOX 1234
VìD"Sxxx PO BOX 1234

1: $str =~ s/"/ /g; removes the " and replaces it with a space (good)

2: $str =~ s/[^!-~\s]/ /g;


Please help: j

Answer

You can try this code:

while(<DATA>)
{
    $_=~s/([^[:ascii:]]|")/ /g;
    print $_;
}


__DATA__
FOìO BAR       PO BOX 1234
LASDìBA"       PO BOX 1234
VìD"Sxxx       PO BOX 1234

Output:

FO  O BAR       PO BOX 1234
LASD  BA        PO BOX 1234
V  D Sxxx       PO BOX 1234