<?xml version="1.0" encoding="windows-1252"?>
<node id="413710" title="regexp for scalar containing a mixture of LF &amp; CRLF" created="2004-12-09 17:52:56" updated="2005-08-04 16:14:26">
<type id="115">
perlquestion</type>
<author id="337321">
NateTut</author>
<data>
<field name="doctext">
Monks;
    I have a scalar containing text with a mixture of line ending characters (it's Lotus Notes e-mail message text). I want to replace all of the LFs to be CRLFs. &lt;BR&gt;
    I have tried many different regexp approaches. Below is the relevant snippet:
&lt;code&gt;
  open (TEXTFILE, "&gt;$subdir/message.txt")
     or die "Can't create $subdir message file: $!";
  print TEXTFILE "From: ", $doc-&gt;{From}-&gt;[0];
  print TEXTFILE "Subject: ", $doc-&gt;{Subject}-&gt;[0];
  $doc-&gt;{Body} =~ s/\015/\n/gm;
  print TEXTFILE $doc-&gt;{Body};
  close TEXTFILE;
&lt;/code&gt;
$doc-&gt;{Body} contains the text with the mixture of LFs &amp; CRLFs. This is a WinDoze app so I'm sure print is putting CRLFs on the line ends. 
&lt;BR&gt;
In the s/ I've tried everything I can think of: \x0D instead of \015 s instead of m at the end, etc. I still end up with extranneous LFs left. I think it's a problem of my understanding of the concept of a line in a regexp or something.
&lt;BR&gt;
&lt;BR&gt;
Doug
&lt;br&gt;&lt;br&gt;
***Update***
here's how I finally got it to work.
&lt;code&gt;
  open (TEXTFILE, "&gt;$subdir/message.txt")
     or die "Can't create $subdir message file: $!";
  print TEXTFILE "From: ", $doc-&gt;{From}-&gt;[0];
  print TEXTFILE "Subject: ", $doc-&gt;{Subject}-&gt;[0];
  my $NewBody = $doc-&gt;{Body};
  $NewBody =~ s/\x0D\n/\n/g;
  print TEXTFILE $NewBody;
  close TEXTFILE;
&lt;/code&gt;

The problem was that I was trying to modify a Lotus Notes Object. Kudos to diotalevi for that tip.
&lt;br&gt;&lt;br&gt;
Doug
Doug</field>
</data>
</node>
