You have used single quotes which don't allow interpolation of variables or escapes so you get a literal
\n rather than a newline. Since you also want double quotes in your output it will be easiest to use quoting constructs,
qq{ ... } for double quotes. You may also want to include carriage returns if the target is DOS, I'm not sure if Perl takes care of this for you if built for that platform. You will have to double up the backslashes and escape the
% sign inside double quotes.
my $outfile = q{mybatchfile.bat};
open( OUTPUT, q{>}, $outfile)
or die qq{Can't open file $outfile : $!\n};
{
print OUTPUT
qq{\@echo off\n setlocal\n set PATHNAME=C:\\TEMP\\\%1_REGRESSIO
+N\n},
qq{set WAIT_TIME=240000\n set URL="http://myurl.biz"\n},
qq{set PWD="megapassword"\nset EMAIL_TO_STRING="bob@test.com"};
}
I hope this is helpful.
Update: Thinking about it, your code might be a lot clearer if you use a HEREDOC.
my $outfile = q{mybatchfile.bat};
open( OUTPUT, q{>}, $outfile)
or die qq{Can't open file $outfile : $!\n};
print OUTPUT <<EOT
@echo off
setlocal
set PATHNAME=C:\TEMP\%1_REGRESSION
set WAIT_TIME=240000
set URL="http://myurl.biz"
set PWD="megapassword"
set EMAIL_TO_STRING="bob@test.com"
EOT
Also, I should have escaped the @ in the first code sample; corrected.
Update: Corrected typo - s{qotes}{quotes}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.