![]() |
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 |
Re: Escaping backslashes in 'HERE documents'?
The sentient life form Jim Ford posted the following:
> print <<"WEEKS"; Try print <<'WEEKS'; which should prevent interpolation. |
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 |
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 $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.