exact print

G

George Mpouras

I need to print a text to file from within the script. The printed text must
be the same as the script text.
I do not want to escape every single character of the text, it should be
"pass through". So far nothing worked.
A small script that expose the problem, any help is wellcome.

open FILE, '>test.txt' or die "$^E\n";
print FILE q~
\
\\
\\\
~;
close FILE;
 
P

panther.mindc

open FILE, '>test.txt' or die "$^E\n";
print FILE <<'F';
\
\\
\\\
F
close FILE;
 
B

bobmct

Again, forgive me George: you've much more experience than I, but I
moved my test program to a Windows image and got this:

C:\WIP>type tryout.pl
use strict;
use warnings;
use 5.010;

use Data::Dumper;

open FILE, '>test.txt' or die "$^E\n"
print FILE <<'F';
\
\\
\\\
F
close FILE;

C:\WIP>type test.txt
\
\\
\\\

C:\WIP>

I was initially suspicious of the apparent extra return at the end of
the file but I looked at test.txt with an editor (inside Win) and there
is only one. The Win shell "type" command seems to add another. So the
output is the same as the Linux version.

What am I missing?

ANother thing you could try is printing with FORMATs. The output will
be EXACTLY as described on the format. I've used this technique to
create fixed format files for transferral to dependent agencies with
excellent results. Runs the same on *nix or *doze.
 
G

George Mpouras

there is a strange behaviour of activestate petl (5.16) at windows

print FILE q~
\
\\
\\\
~;

prints


\
\
\\



print FILE<<stop_printing;
\
\\
\\\
stop_printing

prints

\
\
 
R

Rainer Weikusat

"George Mpouras"
there is a strange behaviour of activestate petl (5.16) at windows

print FILE q~
\
\\
\\\
~;

prints


\
\
\\



print FILE<<stop_printing;
\
\\
\\\
stop_printing

prints

\
\

This is not really strange: A here-document whose delimiter is not quoted is
essentially a "-quoted string. The first \ escapes the newline right
after it. The \\-sequence in the seond line cause a \ to be
printed. The third line results in another \ because of the \\ and the
trailing newline is again escaped (which is a no-op).
 
R

Rainer Weikusat

George Mpouras said:
if so why windows behaviour is completely different than linux ?

When running your two code examples on 'Linux', I get the exact same
output you posted.
 
G

George Mpouras

try to run them on a windows box and compare the results between windows and
linux
 
R

Rainer Weikusat

George Mpouras said:
try to run them on a windows box and compare the results between
windows and linux

I explained the phenomenon you described for 'Linux'. I have no idea
about the behaviours on Windows and - frankly - 'something weird
happening on Windows', isn't that sort-of a tautology? :->
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top