I double checked the code and haven't found any typo:
#!/usr/bin/perl
$file = @ARGV[0];
$out_file = $file.".out";
my $count = 0;
print "Processing file: $file\n";
print "Output file: $out_file\n";
open FILE, "$file" or die "cannot open $file file";
open OUT, ">>$out_file" or die "cannot create $out_file file";
#go through the file rows
while (<FILE>) {
chomp;
# if row contain non-ASCII symbols - it is counted
if ($_ =~ /[[:^ascii:]]/) {
print "String before modification:\n $_ \n";
s/[[:^ascii:]]/q{<} . unpack(q{H2}, $1) . q{>}/eg;
print "String after modification:\n $_ \n";
print OUT "$_\n";
$count++ ; }
else {
print OUT "$_\n";
}
}
print "there are $count possibly corrupted rows\n";
close FILE;
close OUT;
the contents of processed file:
0,1,,,1,~=_<>}[]||$? £??§^`??¿ ?. Qu est çe quil Y a Yå,0,20120
+306101731
0,1,,,1,Teá,0,20120314104403
0,1,,,1,Q<8a>rUì ,0,20120306103345
1,1,,,3,,0,20120331152610
1,1,,,3,,0,20120331152612
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.