×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Text::CSV::Unicode not processing CSV string?

Text::CSV::Unicode not processing CSV string?

Text::CSV::Unicode not processing CSV string?

(OP)
Hi,

I'm having major problems with Perl and wide characters, specifically the GBP (£) pound sign.

If I create my own CSV string and output it to the browser, when I open the CSV file, there is a funny char displayed with the pound sign (£).

So I am trying to create a Unicode CSV string using the Text::CSV::Unicode module, only it won't parse my CSV string.

The line it says it doesn't like is...

Quote:

"Axxxx xxxx xxxx Ltd","Alan Smith","Carl Jones","Legal & General","30/07/2009","524.89","22/07/2011","306.09","24/08/2011","Protection","Reinstatement £306.09
13/12/11 C/B £306.09"

which is found using

CODE

$csv->error_input 

I can only assume it doesn't like the carriage return in the last encapsulated column value, but it should as I have created the object using

CODE

my $csv = Text::CSV::Unicode->new([{ binary => 1 }]); 

And the CPAN docs say

Quote:

new $csv = Text::CSV::Unicode->new( [{ binary => 1 }] );

This function may be called as a class or an object method. It returns a reference to a newly created Text::CSV::Unicode object. binary => 0 allows the same ASCII input as Text::CSV and all other input, while binary => 1 allows for all Unicode characters in the input (including \r and \n),

So there should be no problem with either \r or \n in any of the fields in my input array?

Any ideas how I fix this pound sign problem or get the Text::CSV::Unicode to accept my input?

Thanks,
1DMF

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads

RE: Text::CSV::Unicode not processing CSV string?

(OP)
Well I don't know if it's a typo in the docs or if the square brackets are meant to imply 'optional' as there is another example that uses..

CODE

$csv = Text::CSV::Unicode->new( { binary => 1 } ); 

Which works, only when the XLS file is opened, there is still a funny character in front of the pound sign!

So Text::CSV::Unicode has made no difference?

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads

RE: Text::CSV::Unicode not processing CSV string?

(OP)
It's OK, found the culprit.

It was the IO::File output of the string that was corrupting the data!

CODE

# create an IO::File for Catalyst
    use IO::File;
    my $iof = IO::File->new;
    $iof->open(\$xls, "r");
    $iof->binmode(":encoding(UTF-8)"); 

# output XLS data                              
    $c->response->body($iof);
        
# close file
    undef $iof; 

Once I added the binmode with a UTF-8 encoding layer, it now outputs pound signs correctly smile

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close