difference between print <<EOF ... and print qq(...)

L

lynn.newton

There is a question at the end of this, but bear with me while I
present a little background explaining why the question
came up.

Years ago I became aware that in the Bourne shell using this
syntax:

cat <<EOF
$something
EOF

resulted in creating of a temporary file in /tmp with the text
in it. I doubtthat in today's world of abundant memory that this
is still true in any standard Unix or Linux shell, but as long as it
was, using that syntax resulted in the overheadof undesireable
disk activity that probably most people never knew about.

In Perl, of course one may use similar syntax:

print <<EOF;
$something
EOF

which can be useful particularly if $something is long and
contains formatting,such as in returning HTML code to a browser.

So what I am wondering is whether anyone knows the technical
difference of what goes on internally whether I choose to use:

print qq($something);

versus

print <<EOF;
$something
EOF

I certainly believe Perl does not use temporary disk files.
But intuitively, I am inclined to use the quoted style rather
than <<EOF here documents wherever I can.
 
B

Brian McCauley

So what I am wondering is whether anyone knows the technical
difference of what goes on internally whether I choose to use:

print qq($something);

versus

print <<EOF;
$something
EOF

I certainly believe Perl does not use temporary disk files.
But intuitively, I am inclined to use the quoted style rather
than <<EOF here documents wherever I can.

There's very little difference, indeed Perl's here docs are classed as
(and documented as) a quoting style. You can have both interpolating
and non interploating here-docs.

One small point, I think the content of a here-doc quoted string
necessarily ends with a "\n".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top