Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how can I print multiple lines without escaping '$' and other characters?

Reply
Thread Tools

how can I print multiple lines without escaping '$' and other characters?

 
 
bennett@peacefire.org
Guest
Posts: n/a
 
      09-30-2006
Suppose I want to print multiple lines of output which contain dollar
signs. The following will not work:

print <<EOF ;
A loaf of bread costs $1.
A jug of milk costs $2.
EOF

because Perl will interpret the dollar signs. How can I print it
without having to put a backslash in front of every $ sign?

For example, I want to write a Perl script that prints out another Perl
script as output, I don't want to have to write the second Perl script
once using dollar signs and other special characters, then go back and
insert backslashes in front of every special character.

 
Reply With Quote
 
 
 
 
charley@pulsenet.com
Guest
Posts: n/a
 
      09-30-2006

wrote:
> Suppose I want to print multiple lines of output which contain dollar
> signs. The following will not work:
>
> print <<EOF ;
> A loaf of bread costs $1.
> A jug of milk costs $2.
> EOF
>
> because Perl will interpret the dollar signs. How can I print it
> without having to put a backslash in front of every $ sign?


Here docs are explained here.
http://perldoc.perl.org/perlop.html

Scroll down to 'Regexp Quote-Like Operators'

Chris

 
Reply With Quote
 
 
 
 
Ted Zlatanov
Guest
Posts: n/a
 
      10-02-2006
On 29 Sep 2006, wrote:

> Suppose I want to print multiple lines of output which contain dollar
> signs. The following will not work:
>
> print <<EOF ;
> A loaf of bread costs $1.
> A jug of milk costs $2.
> EOF
>
> because Perl will interpret the dollar signs. How can I print it
> without having to put a backslash in front of every $ sign?
>
> For example, I want to write a Perl script that prints out another Perl
> script as output, I don't want to have to write the second Perl script
> once using dollar signs and other special characters, then go back and
> insert backslashes in front of every special character.


In addition to single-quoting the "EOF" marker as others have
suggested, you could use the __DATA__ marker:

while (<DATA>) { read in the data }

__DATA__
This is my script full of $ signs

I like this approach because it's very easy to open an external file
later by just replacing the file handle name.

Ted
 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How can I use quotes without escaping them using CSV? jeffself Python 5 04-10-2008 12:23 AM
Preserve blank lines when add multiple lines of text to a cell Cah Sableng Javascript 0 04-23-2007 04:46 AM
How can i print from the broweser without displaying the dialog print ? Tamer Ibrahim ASP .Net 3 01-29-2007 10:52 AM
Why does "while (<>) { $x .= $_; } print $x . "\n";" print all input lines? Wolfgang Perl Misc 1 02-13-2004 07:51 PM



Advertisments
 



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