Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference between using print <<EOF; and qq~ 2

Status
Not open for further replies.

garymgordon

Programmer
Apr 5, 2000
307
US
What is or are the differences (specifically) in using one or the other of these two options.


print <<EOF;
blah
EOF

and print qq~
blah
~;


Does anyone know?

Thanks,
Gary

Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer
 
Ok.

Here's another ... from the same.

I saw someone use:

qq{


};

So, in looking at the above ... I thought that the same exact character had to be used to close out the qq . So, I would have thought it had to be:

qq{

{

instead of

qq{

}


What is correct? And why?

Thanks!
Gary
Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer
 
When using qqx, the x can be replaced with a non-paired type of character, such as the tilde (~), in which case the SAME character is used to close it. You can also use a PAIRED type of character, such as parens, square brackets, curly brackets or angle brackets, in which case you MUST use the left one to open the qqx and the right one to close it. There is no difference in the effect of the qqx, just a slight difference in syntax. You can even use a non-printable character to surround the literal in a qqx, such as: qq\002This literal can contain almost anything!\002;

qqx works just like normal quotes in that it encloses a literal expression and variables within the expression ARE interpolated. The advantage is that you can use normal quotes inside a qqx expression without having to escape them, ie
Code:
qq(She said, &quot;Hi!&quot;}
;

I've never seen qqx used with multi-line literals like you showed above, only the &quot;here-doc&quot; form <<LABEL.

Check out the perl docs page perlop under &quot;Quote and Quotelike Operators&quot;.

Note also that the <<LABEL form can use any value for the label, as long as the SAME value is used to end it, without a semicolon on the ending label and the ending label MUST start in column 1.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top