Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Char like "" causing the data parse to fail...

Reply
Thread Tools

Char like "" causing the data parse to fail...

 
 
Prasad Gadgil
Guest
Posts: n/a
 
      07-25-2005
Hi,

I am processing some data in csv format, in my script using Text::CSV.
The parsing fails for certain records. On printing these entries, all
of them show a junk characher "".

This is not visible in the input data but only displayed when error is
printed. How do I handle these records ?

regards,
Prasad

 
Reply With Quote
 
 
 
 
Sherm Pendley
Guest
Posts: n/a
 
      07-25-2005
"Prasad Gadgil" <(E-Mail Removed)> writes:

> I am processing some data in csv format, in my script using Text::CSV.
> The parsing fails for certain records. On printing these entries, all
> of them show a junk characher "".


Perl itself can handle any number of text encodings. Have a look at perldoc
perluniintro for details, but here's a short example. To open a UTF-8 encoded
text file for input, you'd do this:

open(my $fh, '<:utf8', $filename) or die "Error opening $filename: $!";

If the encoding you've specified for a particular file handle doesn't match
that used by Perl internally, both incoming and outgoing text is automatically
converted. This works for both input and output.

So, what you need to do is figure out what encoding is used in the incoming
CSV file, and what's expected in the output. Then, specify that encoding when
you open() those files.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse tree like data like XML by Perl? Davy Perl Misc 2 10-09-2006 04:30 AM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM
the difference between char a[6] and char *p=new char[6] . wwj C++ 7 11-05-2003 12:59 AM



Advertisments