Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   exact print (http://www.velocityreviews.com/forums/t957249-exact-print.html)

George Mpouras 02-04-2013 08:33 AM

exact print
 
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;


panther.mindc@gmail.com 02-04-2013 10:49 AM

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

George Mpouras 02-04-2013 12:56 PM

Re: exact print
 
not good

George Mpouras 02-04-2013 03:18 PM

Re: exact print
 
At linux it is ok. At windows does not behave as should ...

bobmct 02-05-2013 02:21 AM

Re: exact print
 
On Mon, 04 Feb 2013 18:02:45 +0000, Henry Law <news@lawshouse.org>
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::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.

George Mpouras 02-05-2013 09:59 PM

Re: exact print
 
there is a strange behaviour of activestate petl (5.16) at windows

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

prints


\
\
\\



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

prints

\
\

Rainer Weikusat 02-06-2013 12:15 AM

Re: exact print
 
"George Mpouras"
<nospam.gravitalsun.antispam@spamno.hotmail.anispa 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).


George Mpouras 02-06-2013 12:30 PM

Re: exact print
 
if so why windows behaviour is completely different than linux ?

Rainer Weikusat 02-06-2013 12:38 PM

Re: exact print
 
"George Mpouras" <nospam.gravitalsun.extraantispam@hotmail.nospam.c 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.



George Mpouras 02-06-2013 12:48 PM

Re: exact print
 
try to run them on a windows box and compare the results between windows and
linux



All times are GMT. The time now is 08:02 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.