perlron has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
Apologies for so many basic questions. I assure you i am doing my homework before checking with you'll.
Issue1 If any one knows a simpler way to introduce a CRLF into a string rather than first writing a string to a file and then reading it, please let me know or provide a link that would help
THe background issue is that my server guy does not support sendmail so am using an external smtp provider. It turns out their api does not have (or not documented) have access via perl, only curl,ruby,python etc.
Ive got the api working from within my script using the curl command and system().
My only issue is with the CRLF field . I am having to write my mail message to a file using >:crlf and then read it again in order to introduce a newline in the string message.
my $command = " curl -s --user \'api:XXXXX\'"; $command .= " https://api.XXXXX.XX/XX/XXXXX.XX.org/XXXX"; $command .= " -F to=\'name\@domain.com\'"; $command .= " -F subject=\'$subject\'"; $command .= " -F text=\'$message\'"; my $result = system($command);

Update - Issue2 resolved thanks to this perlmonks post I am facing yet another peril with my system($curl) approach. Its creating malformed headers when i return the result of the message.Can u suggest a better coding approach ?
malformed header from script. Bad header={:.register.cgi, referer: htt +p://XXXX.local/cgi-bin/register.cgi
Do not wait to strike when the iron is hot! Make it hot by striking - WB Yeats

Replies are listed 'Best First'.
Re: An optimal way to induce CRLF using perlio
by choroba (Cardinal) on Oct 26, 2014 at 21:42 UTC
    If you just want to replace LF by CR+LF, you can use substititution:
    $message =~ s/\n/\r\n/g;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      i tried hard coding \r\n into the string. I read online that the curl command sends data as ascii, so it wont interpret the \r\n as a CRLF. Thats when i thought of using the :crlf perlio approach i mentioned in the question.
      Do not wait to strike when the iron is hot! Make it hot by striking - WB Yeats
        Shell escapes are weak sauce, use system, use Capture::Tiny
        use Capture::Tiny qw/ capture /; my($stdout, $stderr, $exit) = capture { system '.../curl', ...',"\r\n\r\n..."; };;
Re: An optimal way to induce CRLF using perlio
by Loops (Curate) on Oct 26, 2014 at 21:42 UTC
    Hi Ron. Are you just asking how to substitute CRLF for each LF in the $message variable?
    $message =~ s/\n/\r\n/g;
      the requirement is like the message string has to be constructed from query parameters. so then i need to add newlines in my string..and then ship them off to the curl command.
      Do not wait to strike when the iron is hot! Make it hot by striking - WB Yeats