in reply to Replace new line with white space

G'day Abed,

Is this what you're after:

#!/usr/bin/env perl -l use strict; use warnings; my $data_string = do { local $/; <DATA> }; print "Before replacement: '$data_string'"; $data_string =~ y/\n/ /; print "After replacement: '$data_string'"; __DATA__ Line 1 Line 2 Line 3

Output:

Before replacement: 'Line 1 Line 2 Line 3 ' After replacement: 'Line 1 Line 2 Line 3 '

And, if that doesn't do what you want, please heed earlier advice and indicate exactly what it did produce and how that differed from what you wanted.

-- Ken

Replies are listed 'Best First'.
Re^2: Replace new line with white space
by fattahsafa (Sexton) on Mar 10, 2014 at 21:49 UTC
    Thanks alot Ken, you made my day :) I just edited it by adding \r (I'm using Perl on Windows) and it worked ! --Abed.