Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Escaping backslashes in 'HERE documents'?

Reply
Thread Tools

Escaping backslashes in 'HERE documents'?

 
 
Jim Ford
Guest
Posts: n/a
 
      05-18-2007
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
 
Reply With Quote
 
 
 
 
De Vliegende Hollander
Guest
Posts: n/a
 
      05-18-2007
The sentient life form Jim Ford posted the following:

> print <<"WEEKS";



Try print <<'WEEKS';

which should prevent interpolation.
 
Reply With Quote
 
 
 
 
Jim Ford
Guest
Posts: n/a
 
      05-18-2007
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
 
Reply With Quote
 
Raymundo
Guest
Posts: n/a
 
      05-18-2007
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;

 
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
GridView and Backslashes =?Utf-8?B?TWF0dCBIYW1pbHRvbg==?= ASP .Net 0 05-02-2006 12:21 PM
Escaping backslashes issue with printf/grep/popen! agarwalpiyush@gmail.com C Programming 4 12-11-2005 01:22 PM
Save String that contains a windows file path with backslashes peter.o.mueller@gmx.de Java 1 09-05-2005 07:51 PM
Double BackSlashes Mikheil C++ 6 08-15-2003 05:00 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments