Gossamer Forum
Home : General : Perl Programming :

Code inside a qq~ statement

Quote Reply
Code inside a qq~ statement
How do I place code inside a print qq~ statement so that perl does not see it and produce an error?

Example:

print qq~

<font> html, html etc... code to display....> sub { .... } more html to display....

~;

Crazy


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Code inside a qq~ statement In reply to
Try escaping your curly brackets. Or quoting their ASCII number if they are to be displayed in HTML.

- wil
Quote Reply
Re: [Wil] Code inside a qq~ statement In reply to
Thanks Wil... I'll try escaping. Seems a little tedious though. I guess another way is to move it out of this display into another file... but that is not really the answer.

I tried puttin the code inside a text area box between the qq~ and ~; but this did not help, as it still sees the code in the area box.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Code inside a qq~ statement In reply to
Going back on this thread; something is not right here. If you're doing exactly what you quoted in your first message then there shouldn't be a problem. Perl will just output whatever that is in between your qq~ ~; statements. What exactly is the block your outputting? You're not trying to print any semi-colons are you?

- wil
Quote Reply
Re: [Wil] Code inside a qq~ statement In reply to
Yes, I am trying to print a Links Global verbatim... so yes, it is full of semi colons!

Example:

sub {
my $tags = shift;
my $username = $tags->{Username};
my $login = '';
if ($username){ $login = "You are currently logged in as: $username"; }
else{ $login = "You are not logged in" }
return $login;
}


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 1, 2002, 12:37 PM
Post deleted by Mark Badolato In reply to
Quote Reply
Re: [Ian] Code inside a qq~ statement In reply to
Semi-colons aren't an issue, for example:

print qq|;|;

...will work fine.

If you want to put perl code inside prints so that the code isn't interpreted and you don't have to escape everything (which is silly if you have a lot of code) you use q or a single quote eg....

#!/usr/bin/perl


my $var = q|Test|;

print "Content-type: text/html\n\n";
print "Value: $var<br>";
print 'Scalar: $var<br>';
print qq|Value: $var<br>|;
print q|Scalar: $var|;[/code]
But I don't see where that comes into your global above.

Last edited by:

Paul: Jun 2, 2002, 1:40 AM
Quote Reply
Re: [Paul] Code inside a qq~ statement In reply to
Thanks Paul.

Your tips make sense. I have since removed the global from the print page, and the code compiled. So I am not exactly sure was causes the error either?

Dumb question though: I notice you use the pipe (|) symbol rather than the tild (~), does this make a difference?


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Code inside a qq~ statement In reply to
No you can use different delimiters and they work the same, you would just change them so that code inside them didn't break it eg...instead of:

print qq| Menu | Menu |;

You'd do:

print qq~ Menu | Menu ~;

If you want to be confusing you could do:

print qq;Hello;;
Quote Reply
Re: [Paul] Code inside a qq~ statement In reply to
Paul, if I knew half of what you do about Perl!

Very cool. I think you should make the Links for Dummies book Wink

I think I will avoid the print qq;Hello;; version... it will be Perl Checking my code for the rest of my days!


http://www.iuni.com/...tware/web/index.html
Links Plugins
Post deleted by Ian In reply to