in reply to Chomp in perl
Hello sar123,
You just need to move the line:
$/ = "\n+";
to before the line:
my @file = <$fh>;
so that the input record separator (which tells Perl what your “lines” are) is in effect when the file is read in. Then the script works as expected:
use warnings; use strict; use diagnostics; $/ = "\n+"; my @file = <DATA>; chomp (@file); print "@file\n"; __DATA__ xabcd a1 +b1 +b2 +b3 +b4 +b5 abcd xcdef c1 +d1 +d2 +d3 +d4 +cdef
Output:
16:14 >perl 1042_SoPW.pl xabcd a1 b1 b2 b3 b4 b5 abcd xcdef c1 d1 d2 d3 d4 cdef 16:14 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Chomp in perl
by sar123 (Novice) on Oct 05, 2014 at 06:17 UTC |