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


In reply to issue with Encode::Guess by toohoo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.