keep new lines when printing scalar

Y

yeti349

Hi,

I am storing formatted data into a scalar and attemping to print it to
a new file. The formatting, like new lines, is lost because everything
is concatenated. How can i keep my new lines? Thank you.
 
S

Stephen O'D

can you post some sample code? New lines etc are preserved when you
store them in a scalar, unless you chomp them off:-

$more testfile
this
is
my
test
file
contents

-------------------------------------

open ($f,"testfile")
|| die "failed top open file $!\n";

my $data;

while (<$f>) {
$data .= $_;
}

open ($o,">newtestfile")
|| die "Failed to open the out file $!";

print $o $data;

close $f;
close $o;

------------------------------------

$ more newtestfile
this
is
my
test
file
contents

The old and new files are identical ...
 
A

A. Sinan Unur

I am storing formatted data into a scalar and attemping to print it to
a new file. The formatting, like new lines, is lost because everything
is concatenated. How can i keep my new lines? Thank you.

Please read the posting guidelines for this group.

See also <URL:http://perl.plover.com/Questions4.html> as
well as item #11939 in

<URL:http://groups-beta.google.com/group/comp.lang.perl.misc/msg/b2f911d6d9c5cef2?dmode=source>

How do you expect us to help you if we don't have any idea
what the code and the data look like?

Sinan
 
J

Joe Smith

I am storing formatted data into a scalar and attemping to print it to
a new file. The formatting, like new lines, is lost because everything
is concatenated. How can i keep my new lines? Thank you.

New lines are not lost when strings are concatenated, unless you have
explicitly removed them. If you remove newlines, it is your
responsibility to put them back in at the appropriate places.

Are you using chomp()? Please post your code.
-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top