Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: UTF-8 issues with Perl in general and with Spreadsheet::WriteExcel

by jmcnamara (Monsignor)
on Jul 16, 2010 at 15:30 UTC ( [id://849995]=note: print w/replies, xml ) Need Help??


in reply to UTF-8 issues with Perl in general and with Spreadsheet::WriteExcel


Here is a complete example of reading UTF-8 data from a file and writing it to a Spreadsheet::WriteExcel file from the S::WE docs.

Essentially it boils down to this:

open FH, '<:encoding(utf8)', $file or die "Couldn't open $file: $ +!\n"; my $row = 0; while (<FH>) { chomp; $worksheet->write($row++, 0, $_); }

There are several other Unicode examples in that document as well.

--
John.

  • Comment on Re: UTF-8 issues with Perl in general and with Spreadsheet::WriteExcel
  • Download Code

Replies are listed 'Best First'.
Re^2: UTF-8 issues with Perl in general and with Spreadsheet::WriteExcel
by elef (Friar) on Jul 29, 2010 at 07:28 UTC
    The Spreadsheet::WriteExcel issue got cleared up after the first answer, everything is fine with that. Thanks for the link, though, John, it proved to be pretty handy.

    I made a couple of meek attempts at finding out what is wrong with input from console, without success. I take input from the keyboard with <STDIN>, save it in a scalar variable and write it to a utf-8 txt file, the characters get corrupted. If I binmode STDIN beforehand, I get an error message about characters not mapping to Unicode and get character codes like \x{38232E2}\x81\xA1 in the output txt. Fixing this on my own system is not the goal; this is for a script I'm distributing quite widely so it should work on any random computer (with Windows, Mac OS or Linux...)

    As it stands, I think I'll just tell the users to stick to ASCII or they may get corrupted characters. No drama, but it's a bit annoying to have to do that.

    Here's the code in case somebody wants to poke it or has an idea:
    binmode STDIN, ':encoding(utf8)'; print "\nEnter text: "; chomp ($text = <STDIN>); open (TEST, ">:encoding(UTF-8)", "test.txt") or die "Can't open file: +$!"; print TEST $text;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://849995]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-26 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found