Gossamer Forum
Home : Products : Links 2.0 : Discussions :

Problem with that "print qq~" thing

Quote Reply
Problem with that "print qq~" thing
Well, it started with a problem with search.cgi but I've just narrowed it down to this:

If I have a script that looks like this:

Code:
#!/local/bin/perl

print "Content-type: text/html\n\n";


print "<html>";

print "<head>";
print "<title>Ye</title>";
print "</head>";

print "<body>";

print "<h1>Ye</h1>";

print "</body>";
print "</html>";

Everything works fine. But if I do this:

Code:
#!/local/bin/perl

print "Content-type: text/html\n\n";

print qq~

<html>

<head>
<title>Ye</title>
</head>

<body>

<h1>Ye</h1>

</body>
</html>

I get automatically bumped to the directory where the script is and I get a "Forbidden" server error.

Help. Smile

GL
lafranc@cam.org
Quote Reply
Re: Problem with that "print qq~" thing In reply to
You need to close it with ~;

Dan Smile
Quote Reply
Re: Problem with that "print qq~" thing In reply to
Ah...hum...well, I just forgot to write it in the message. It's in the actual script.

Nevertheless, the original problem is that in site_html.pl, everything in printed out with those qq~ thingies and search.cgi, which refers to site_html.pl, doesn't work when I execute it. But I guess that if in site_html.pl everything was printed out with the print ""; syntax, search.cgi would work fine.

GL
lafranc@cam.org

[This message has been edited by Guillaume LAfrance (edited July 19, 1999).]
Quote Reply
Re: Problem with that "print qq~" thing In reply to
>> But I guess that if in site_html.pl
>> everything was printed out with the
>> print ""; syntax, search.cgi would work fine.

The way perl is defined, the "" notation is the 'default' (meaning assumed without further clarification) but the qq<delimeter><delimeter> is the 'generic' (meaning can be adapated to your specific string).

In otherwords, "" is the shorthand for the qq<delimeter><delimeter> notation, so both should work in any context if they used
properly.

print "one-line string";

is linguistically/functionally equivalent to:

print qq~
possible
multiline
string
~;

*ALL* characters need to be escaped ie: '\' since qq notation is the same as "" notation which performs variable and character substitutions.