Greetings Monks, I have a csv file which I'll use Perl to read in and do some manipulations and then output it in a new .csv file. Snippet of the input file: (Three lines each starting with the word "Map")
Map,Adèle,F,Blanc,BLANC Adèle,014596,014596,XEX-MRIJDVASSC-R3,,NOTE:BL +ANC Adèle (014596)@EX%SMTP:adele.blanc@cc.com%X400:c=CA;a= ;p=OH;o=Mr +ijdvasscAR3;s=BLANC;g=Adele;,p:046963@mail,Customer Srv Centre,WORKS/ + SRV,SUPPORT/ SUPPORT,AXD3, + 1123,(603) 489-2365,(603) 254-7458,,,13 + Wood Dr,Vancouver,ON,CAN,J7G 3Y4,/o=O:ou=AR3/337610, Map,William,,Lemond,LEMOND Will,112477,112477,XEX-MC-A,,SMTP:Will.lemo +nd@cc.com%LEMOND Will@EX%X400:c=CA;a= ;p=OH;o=MC;s=Lemond;g=Will;,,Ma +int,,M STAT,AC,6224,,,,,,,,,,, Map,Jacky,L,Mack,MACK Jacky,923636,923636,XEX-MNHYI-R3,,NOTES:MACK Jac +ky (923636)@EX%SMTP:Jacky.Mack@cc.com%X400:c=CA;a= ;p=OH;o=MR3;s=MACK +;g=Jacky;,p:@mail,Electrical,WORKS/ STS,OTT,K94, +,,,,,1501 Karten Ro +ad,Ottawa,ON,CAN,N7Q B5L,/o=OH/u=MR3/k,
If I use the following code on the snippet of input file above, only the second and third line gets printed in the output file. The first line just got ignored. I am using Perl 5.8 on a Unix machine.
#!/usr/local/bin/perl use strict; use Text::CSV_XS; my ($mday, $mon, $year) = (localtime(time))[3..5]; my $cdate = sprintf "%02d" x 3, $mon+1, $mday, $year%100; my $infile = "inmail.csv"; my $outfile = "outmail${cdate}.csv"; if ( open( INFILE, "<:utf8", $infile ) ) { open (OUTFILE, ">:utf8", $outfile); my $csv = Text::CSV_XS->new(); while (defined(my $line = <INFILE>)) { next if $. == 1; chomp $line; if (my $status = $csv->parse($line)) { my @columns = $csv->fields; @columns = quotecolumn(@columns); for (9) { $columns[$_] =~ s/^.*SMTP://; $columns[$_] =~ s/\%.*$//; $columns[$_] =~ s/\".*$//; } print OUTFILE join(",", @columns[1,2,3,4,5,9,11,12,13,15,1 +6,17,18,19,20,21,22,23,24]), "\n"; } } close (INFILE); close (OUTFILE); } sub quotecolumn { my @columns = @_; for (@columns) { if (/,/) { unless (/^"[^"]*"$/) { $_ = qq("$_"); } } } return @columns; }
If I remove è in Adèle in the first line, all three lines get printed in the output file. I am guess this is unicode problem? but I've tried using utf8, binmode but it doesn't work. I'm a beginner in Perl and any help would be appreciated. Thanks in advance!

In reply to french character in input file. by hotpower

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.