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

Discussion in 'Perl Misc' started by Prasad Gadgil, Jul 25, 2005.

  1. 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
     
    Prasad Gadgil, Jul 25, 2005
    #1
    1. Advertising

  2. "Prasad Gadgil" <> 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
     
    Sherm Pendley, Jul 25, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keithb
    Replies:
    1
    Views:
    433
    Mark Fitzpatrick
    Oct 30, 2006
  2. Replies:
    19
    Views:
    1,171
    Daniel Vallstrom
    Mar 15, 2005
  3. lovecreatesbeauty
    Replies:
    1
    Views:
    1,132
    Ian Collins
    May 9, 2006
  4. Clint Olsen
    Replies:
    5
    Views:
    160
    Clint Olsen
    Feb 9, 2004
  5. Davy
    Replies:
    2
    Views:
    153
Loading...

Share This Page