#!/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.pl (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 = ; close (GETFILEDAT); $/ = $orgein; return ($content); }