M15U has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Chomp doesn't work
by davido (Cardinal) on Mar 25, 2013 at 09:04 UTC | |
by M15U (Acolyte) on Mar 25, 2013 at 09:22 UTC | |
by daxim (Curate) on Mar 25, 2013 at 12:31 UTC | |
by jwkrahn (Abbot) on Mar 25, 2013 at 18:53 UTC | |
by choroba (Cardinal) on Mar 25, 2013 at 23:49 UTC | |
Re: Chomp doesn't work
by daxim (Curate) on Mar 25, 2013 at 08:59 UTC | |
Re: Chomp doesn't work
by demerphq (Chancellor) on Mar 25, 2013 at 14:26 UTC | |
by M15U (Acolyte) on Mar 26, 2013 at 07:52 UTC | |
by Anonymous Monk on Mar 26, 2013 at 08:32 UTC | |
by soonix (Chancellor) on Mar 26, 2013 at 08:31 UTC |