Antec1981 has asked for the wisdom of the Perl Monks concerning the following question:

I just switch to a new server that runs redhat 8 and perl 5.8....
I am reading a file into $buf using
while(read(filehandle,$buf,60*57){ $unf .=encode_base64($buf); }
This has worked fine for me in the past... as 57 bytes is
equal to one line of base64 code...

But now i keep getting Wide Characters in Subroutine and
perl dies.


Now i created a smaller script....
#!/usr/bin/perl use MIME::Base64; $imgpath = "/home/freexxxm/public_htmlews_photos"; # Ed. - rot13ed to make firewall safe $cat="Nany-Frk"; open (LOG, ">> log2"); opendir (DM, "/home/usr/public_htmlews_photos") or print "$today <b>E +RROR</b> couldn't get contents of <br>dir $!\n" ;<br> @files=grep { /\.jpg/ } readdir(DM); closedir(DM); $img=$files[rand(@files)]; while ($seen){$img++}; $img; print "$img $!\n"; open(FILE, "$imgpath/099.jpg") or print LOG "$today <b>ERROR</b> openi +ng image while posting $!\n";<br> while (read(FILE, $buf, 60*57)) { print LOG"$buf$!"; $unf .=encode_base64($buf); } print "$unf"; close FILE; close LOG;
I have run this 2 way one way i just looked at the print
out of $buf which dies partiall thru with "Malformed
Uft-8 character" and ive run it the way the code
shows now ... and the encode_base64 give me the
same "Wide Character in subroutine" error. Please
could someone explain what this is and whats causing
it ... and how to fix this....

update (broquaint): added formatting and rot13ed the contents of $cat for naive firewalls

Replies are listed 'Best First'.
Re: UFT-8 Error
by graff (Chancellor) on Jul 04, 2003 at 04:10 UTC
    This relates to a "feature" of 5.8.0, possibly made worse by something peculiar to RedHat 8 and its handling of "locale" settings. I believe it will not be a feature of 5.8.1 (that is, people recognize this as a bug that needs fixing).

    Basically, despite your intention of reading raw bytes from a non-text data file, your RedHat "locale" is inducing Perl 5.8.0 to treat non-ASCII data as if it were intended to be utf8. (The actual problem may need a more detailed description, but I think I captured the essence of it.)

    Until 5.8.1 comes out, you have a work-around: insert this line into your script, near the top:

    use bytes;
    That should disable any hidden agendas about treating stuff as utf8. If I'm wrong about that, check the "perlunicode" man page -- that should explain things better and more accurately.
Re: UFT-8 Error
by xdg (Monsignor) on Jul 04, 2003 at 11:45 UTC

    Another alternative is probably to turn off the UTF8 locale in RH8. Look in your /etc/sysconfig/i18n file and change the LANG line from "en_US.UTF-8" to just "en_US".

    -xdg

    Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk.