Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Escaping backslashes in 'HERE documents'? (http://www.velocityreviews.com/forums/t903136-escaping-backslashes-in-here-documents.html)

Jim Ford 05-18-2007 08:03 PM

Escaping backslashes in 'HERE documents'?
 
Is there a way of avoiding having to escape a backslash character with
another backslash in a 'HERE document'?

When creating Latex documents with a perl script, it's convenient to use
'HERE documents'. This enables Latex code to be written without the
clutter of 'print', double quotes, newline characters and semicolons -
producing almost 'clean' Latex coding. The only thing preventing 'pure'
Latex code being written is the necessity of escaping the ubiquitous
backslash character with another backslash - which ends up with this
sort of thing being created:

print <<"WEEKS";
\\begin{tabular}{|c||r|c|c|c|c|c|c|c|c|c|c|}
\\hline
& & {\\textbf{\\ 1\\ \\ }} &{\\textbf{\\ 2\\ \\ }} .... and so on


Jim Ford

De Vliegende Hollander 05-18-2007 08:20 PM

Re: Escaping backslashes in 'HERE documents'?
 
The sentient life form Jim Ford posted the following:

> print <<"WEEKS";



Try print <<'WEEKS';

which should prevent interpolation.

Jim Ford 05-18-2007 09:50 PM

Re: Escaping backslashes in 'HERE documents'?
 
De Vliegende Hollander wrote:
> The sentient life form Jim Ford posted the following:
>
>> print <<"WEEKS";

>
>
> Try print <<'WEEKS';
>
> which should prevent interpolation.


Thanks, but I need interpolation because I've got perl scalars in the
'Here document' e.g.:

\\textbf{$day} & \\textbf{Thursday} & & & & & & & & & & \\\\

Jim Ford

Raymundo 05-18-2007 11:30 PM

Re: Escaping backslashes in 'HERE documents'?
 
On 5¿ù19ÀÏ, ¿ÀÀü6½Ã50ºÐ, Jim Ford <jaf...@watford53..freeserve.co.uk> wrote:
> De Vliegende Hollander wrote:
> > The sentient life form Jim Ford posted the following:

>
> >> print <<"WEEKS";

>
> > Try print <<'WEEKS';

>
> > which should prevent interpolation.

>
> Thanks, but I need interpolation because I've got perl scalars in the
> 'Here document' e.g.:
>
> \\textbf{$day} & \\textbf{Thursday} & & & & & & & & & & \\\\
>
> Jim Ford



Hello,

I tried the following... It seems to work as what you want. But there
might be another problem. :-)

#!/usr/bin/perl
$day = "2007.5.19";

# At first, use single quote and nothing is interpolated
$str=<<'EOF';
\textbf{$day} & \textbf{Thursday} & & & & & & & & & & \\
EOF

# Now replace single backslash with double backslashes
$str =~ s/\\/\\\\/g;
# Perform interpolation
eval '$str="'.$str.'";';
# Print
print $str;



All times are GMT. The time now is 06:01 PM.

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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57