don't try to decode utf-8 strings
[webpac2] / lib / WebPAC / Input / CSV.pm
index 7dcf582..fc11be7 100644 (file)
@@ -67,7 +67,17 @@ sub new {
                $rec->{'000'} = [ ++$self->{size} ];
 
                my $col = 'A';
-               $rec->{ $col++ } = Encode::decode_utf8( $_ ) foreach @$line;
+               foreach my $cell ( @$line ) {
+                       my $str = eval { Encode::decode_utf8( $cell ) };
+                       if ( $@ ) {
+                               if ( $@ =~ m/Cannot decode string with wide characters/ ) {
+                                       $str = $cell;
+                               } else {
+                                       die "ERROR: $@ in line ",dump( $line );
+                               }
+                       }
+                       $rec->{ $col++ } = $str;
+               }
 
                push @{ $self->{_rec} }, $rec;