http://qs321.pair.com?node_id=1210304


in reply to Re: By the shine on my bald pate, I dislike this encoding stuff
in thread By the shine on my bald pate, I dislike this encoding stuff

This doesn't explain why it doesn't work but OK, thanks, I have added:

use Encode::Guess; my $decoder = Encode::Guess->guess($filedata); # default detectable e +ncodings include utf8. return(@err, "Can't guess encoding: $decoder") unless ref($decoder);

This is still no good as it fails for all files, ANSII and UTF-8 with error

Can't guess encoding: Empty string, empty guess.

Replies are listed 'Best First'.
Re^3: By the shine on my bald pate, I dislike this encoding stuff
by poj (Abbot) on Mar 04, 2018 at 09:01 UTC
    Empty string

    All the content is read into @LINES so $filedata is empty

    my(@LINES) = <ORDERFILE>;
    my $filedata = <ORDERFILE>;
    

    Maybe try

    my @LINES = <ORDERFILE>;
    my $filedata = join '',@LINES;
    

    or just

    open ORDERFILE, '<', $emailfile or die "$emailfile: $!";
    my $filedata = do { local $/; <ORDERFILE> };
    close ORDERFILE;
    
    poj

      Thank you. I had no idea. That does work for the files that are ANSI. Most bizarrely,

      my @LINES = <ORDERFILE>; my $filedata = join '',@LINES;

      works but the following does not + I get loads of warnings: "utf8 "\xA3" does not map to Unicode"

      my $filedata = <ORDERFILE>;
        my $filedata = <ORDERFILE>;

        That only reads the first line of the file.

        poj