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