Say I have this line of input from a file:
|decoraw@act.org|This is my message.\\nI hope these returns will work +this time.\\nWendy|http://www.act.org|3|3|
And this perl script:
#!/usr/bin/perl $mailprog = '/usr/sbin/sendmail -t'; $admin_email="decoraw\@act.org"; $subject="Testing the new mass mailer"; $file = "/actapps/suitespot/cgi-bin/sender/returntest3.txt"; $number_sent = 0; open(DATA, "$file") || die "Can't open $file"; # open the file for +reading while($line = <DATA>) { chomp $line; ($junk,$email,$message,$survey_url,$login,$password) = split(/\|/, +$line); $message =~ s|\\n|\n|g; #replace the escaped newlines with newlin +es for formatting open (MAIL, "|$mailprog -t") || die "Can't open $mailprog! \n"; print MAIL "Content-type:text/plain\n"; print MAIL "From: $admin_email\n"; print MAIL "To: $email\n"; print MAIL "Subject: $subject\n"; print MAIL "$message\n\n"; print MAIL "URL: $survey_url\n"; print MAIL "Login: $login\n"; print MAIL "Password: $password\n"; close(MAIL); $number_sent++; }
And I get this output in an email:
This is my message.\ I hope these returns will work this time.\ Wendy URL: http://www.act.org Login: 3 Password: 3
What is wrong with my regex  $message =~ s|\\n|\n|g;  #replace the escaped newlines with newlines for formatting that is causing the new lines to be inserted but one \ to remain? I've tried several variations on the regex, but this is the only one i've been able to actually get the newlines showup properly. TIA -Wendy

In reply to escaping newlines, regex question by hmbscully

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.