in reply to problem in printing the result in the out put file
Your input data probably contains an extra \r that is not removed by chomp. You can see that with Data::Dump:
One of the ways this can happen is when you try to read a file created on Windows with perl running on Linux, or a Cygwin perl.use Data::Dump qw( pp ); # some code here print pp \@ip; chomp(@ip); print pp \@ip;
You can correct that by explicitly setting the input record separator to the CRLF format:
my @ip; { local $/ = "\r\n"; # because this is local, the normal behaviour is +restored after this block open my $dat, "<", $in_file or die "Can't open file $in_file: $!"; @ip = <$dat>; chomp(@ip); close $dat; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problem in printing the result in the out put file
by johngg (Canon) on Feb 28, 2017 at 19:12 UTC | |
by Eily (Monsignor) on Feb 28, 2017 at 19:46 UTC |