Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Chomp in perl

by Athanasius (Archbishop)
on Oct 05, 2014 at 06:12 UTC ( [id://1102852]=note: print w/replies, xml ) Need Help??


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
    Thanks again...:)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1102852]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-16 03:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found