Dear monks

Could you help me fix this bug ? The chomp command does not seem to work. Here is my program. I knlow I have asked about a smilar problem but this time, it seems that chomp does not seem to work, at least on csv files.

#!/usr/bin/perl use strict; my $c_inFile = q{countries_list.csv}; open my $c_INFILE, q{<}, $c_inFile or die "Can't open countries_list.c +sv : $!"; my $c_outFile = q{test_list.csv}; open my $c_OUTFILE, q{>}, $c_outFile or die "Can't open countries_list +.csv : $!"; my $country; while (my $line = <$c_INFILE>){ chomp($line); my @Elements = split(";",$line); $country = $Elements[0]; print $c_OUTFILE "the country is p${country}p\n"; } close $c_INFILE; close $c_OUTFILE;

Here is my input file

Italy USA France

Here is my output file

the country is pItaly p the country is pUSA p the country is pFrance p
But when my input file is
Italy;1 USA;1 France;1

The output file is

the country is pItalyp the country is pUSAp the country is pFrancep

In reply to the chomp does not seem to work by steph_bow

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.