Hello monks

I have this rather silly problem with a piece of code :

I have a ".txt" file with the following lines :

1998.03.25.01

1999.10.01.01

Parameter 1

Parameter 2

There is no 'new line' between each line of the file.

And this code :

#!/usr/bin/perl -w use strict; use locale; use warnings; #use diagnostics; use utf8; binmode(STDIN, "encoding(utf8)"); binmode(STDOUT, "encoding(utf8)"); binmode(STDERR, "encoding(utf8)"); my $usr_input = "test/test.txt"; open (USRIN, '<:utf8', $usr_input) || die "Couldn't open $usr_input : +$!\n"; my @data_usr = <USRIN>; my $start_input = $data_usr[0]; my $end_input = $data_usr[1]; my $param1 = $data_usr[2]; my $param2 = $data_usr[3]; print "$start_input"; print "$end_input"; print "$param1"; print "$param2"; close (USRIN);

Everything works, but I always seem to get a new line in my variables. I tried everything : chomp (@data_usr), or chomping first URSIN in a while loop, or chomping each new variable. It seems that each time chomp removes all the characters not only the "\n" one.

What am I doing wrong ? I know it's a really newbie question.

Thank you


In reply to Chomp doesn't work by M15U

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.