toohoo has asked for the wisdom of the Perl Monks concerning the following question:
Hello everybody
I have an issue with Encode::Guess. I don't know what I'm doing wrong.
I want to guess the encoding of a file.
#!/usr/bin/perl use strict; use warnings; print "2utf8.pl\n"; use Encode; use Encode::Guess; #my @encs = Encode->encodings(":all"); #print join("--",@encs); push( @INC, '.'); #use sniver; our $data; if( $ARGV[0] eq '') { print "no ARGV[0]?: $ARGV[0]\n"; usage(); } elsif ($ARGV[0] ne '') { print "IS ARGV[0]: $ARGV[0]\n"; $data = getfile($ARGV[0]); if($data){ print length($data),"--\n"; print "length(data)>0\n"; }else{ print "lenght(data)<=0\n"; #my EIN; abor("getfile no success"); } } else { print "no ARGV[0]?: $ARGV[0]\n"; } my $encodings_test = 'ascii cp1252 cp437 cp850 iso-8859-1 utf-8-strict + utf8'; my $decoder = guess_encoding($data, qw/$encodings_test/); print "decoder: $decoder\n"; sub usage { print "2utf8.pl - thomas hofmann (c) Apr 2020\nUSAGE: perl 2utf8.p +l (file)\n"; } sub mes { my $mes = shift; if($mes){ print "$mes"; if($mes !~ m/\n$/){print "\n";} } } sub abor { my $mes = shift; if($mes){ mes( "Error: $mes" ); if($mes !~ m/\n$/){print "\n";} } usage(); exit(1); } sub getfile { my ($filepath, @rest) = @_; my $content = undef; my $orgein = $/; local (*GETFILEDAT); if (!open(GETFILEDAT, $filepath)) { return ($content); } undef ($/); binmode(GETFILEDAT); $content = <GETFILEDAT>; close (GETFILEDAT); $/ = $orgein; return ($content); }
The used file is the following ABC.dcm file
* Datensatz: XXX * Erzeugt von: Hofmann, Thomas * Datum: 24.05.2019 08:06:27 * * ASE DCEnv ComponentV2.6.0.2243 KONSERVIERUNG_FORMAT 2.0 FESTWERT AAA LANGNAME "Querbeschleunigunge" EINHEIT_W "-" WERT 0.8000000119 END FESTWERT BBB LANGNAME "Rollzentrumshoehe" EINHEIT_W "m" WERT 0.4600000083 END FESTWERT CCC LANGNAME "Sportmodus" EINHEIT_W "m" WERT 0.4699999988 END FESTWERT DDD LANGNAME "Aufbaumasse" EINHEIT_W "kg" WERT 1850.000000 END FESTWERT EEE LANGNAME "Federsteifigkeit" EINHEIT_W "N/mm" WERT 25 END FESTWERT FFF LANGNAME "Vorderachse" EINHEIT_W "N/mm" WERT 22 END FESTWERT GGG LANGNAME "Momentenverteilung abhängig" EINHEIT_W "m/s^2" WERT 0.5 END FESTWERT HHH LANGNAME "abhängig der Querbeschleunigung" EINHEIT_W "-" WERT 0.25 END
Thanks in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: issue with Encode::Guess
by Corion (Patriarch) on Apr 04, 2020 at 18:24 UTC | |
by toohoo (Beadle) on Apr 05, 2020 at 10:51 UTC | |
by Corion (Patriarch) on Apr 05, 2020 at 11:01 UTC | |
by ikegami (Patriarch) on Apr 06, 2020 at 14:08 UTC | |
by toohoo (Beadle) on Apr 06, 2020 at 04:46 UTC | |
|
Re: issue with Encode::Guess
by 1nickt (Canon) on Apr 04, 2020 at 20:14 UTC | |
by toohoo (Beadle) on Apr 05, 2020 at 14:55 UTC | |
by 1nickt (Canon) on Apr 05, 2020 at 16:13 UTC |