Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > exact print

Reply
Thread Tools

exact print

 
 
George Mpouras
Guest
Posts: n/a
 
      02-04-2013
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;

 
Reply With Quote
 
 
 
 
panther.mindc@gmail.com
Guest
Posts: n/a
 
      02-04-2013
open FILE, '>test.txt' or die "$^E\n";
print FILE <<'F';
\
\\
\\\
F
close FILE;
 
Reply With Quote
 
 
 
 
George Mpouras
Guest
Posts: n/a
 
      02-04-2013
not good
 
Reply With Quote
 
George Mpouras
Guest
Posts: n/a
 
      02-04-2013
At linux it is ok. At windows does not behave as should ...
 
Reply With Quote
 
bobmct
Guest
Posts: n/a
 
      02-05-2013
On Mon, 04 Feb 2013 18:02:45 +0000, Henry Law <(E-Mail Removed)>
wrote:

>On 04/02/13 15:18, George Mpouras wrote:
>> At linux it is ok. At windows does not behave as should ...

>
>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:umper;
>
>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.
 
Reply With Quote
 
George Mpouras
Guest
Posts: n/a
 
      02-05-2013
there is a strange behaviour of activestate petl (5.16) at windows

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

prints


\
\
\\



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

prints

\
\
 
Reply With Quote
 
Rainer Weikusat
Guest
Posts: n/a
 
      02-06-2013
"George Mpouras"
<(E-Mail Removed) m.com.nospam>
writes:
> 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).

 
Reply With Quote
 
George Mpouras
Guest
Posts: n/a
 
      02-06-2013
if so why windows behaviour is completely different than linux ?
 
Reply With Quote
 
Rainer Weikusat
Guest
Posts: n/a
 
      02-06-2013
"George Mpouras" <(E-Mail Removed) om>
writes:
> 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.


 
Reply With Quote
 
George Mpouras
Guest
Posts: n/a
 
      02-06-2013
try to run them on a windows box and compare the results between windows and
linux

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
print a vs print '%s' % a vs print '%f' a David Cournapeau Python 0 12-30-2008 03:19 AM
Problem - I want to print Current Output of Pdf file and should print once.I get print dialog box but it is not working keto Java 0 05-30-2007 11:27 AM
eXact.downloader =?Utf-8?B?ZmFuYm90?= Microsoft Certification 0 05-14-2005 02:08 AM
Which exact version? David Harrison Firefox 3 09-25-2004 04:02 PM
Unlarging the print to print using PDF file to print Bun Mui Computer Support 3 09-13-2004 03:15 AM



Advertisments