Here is what I have:
sub DoNewsHTML {
if ($uservar1 ne "") {
$newshtml .= qq~ <p><strong><a href="$uservar1" target="_blank">$newssubject</a> </strong><br><font size="2">Posted
$newsdate by <a href="mailto:$newsemail">$newsname</a><br> ~;
}
$newshtml .= qq~ <p><strong>$newssubject</strong><br><font size="2">Posted
$newsdate by <a href="mailto:$newsemail">$newsname</a><br> ~;
}
if ($uservar1 ne "") {
$newshtml .= qq~ <img src="$uservar3" align="right" border="0"></a> ~;
}
$newshtml .= "</p>";
}
$newstext<br> ~;
if ($uservar1 ne "") {
$newshtml .= qq~ <i>Source: <a href="$uservar1" target="_blank">$uservar2</a></i> ~;
}
$newshtml .= "</p>";
}
When I try to run the program, I get a fatal error. Can anyone tell me what I'm doing wrong? I think I have some extra brackets or something. I'm also a little unsure about the conditions. If you see the problem, it would be great if you could just fix it for me.
Just for reference, when I use the following code, everything works fine.
sub DoNewsHTML {
$newshtml = qq~ <p><strong><a href="$uservar1" target="_blank">$newssubject</a> </strong><br><font size="2">Posted
$newsdate by <a href="mailto:$newsemail">$newsname</a><br>
$newstext<br> ~;
if ($uservar1 ne "") {
$newshtml .= qq~ <i>Source: <a href="$uservar1" target="_blank">$uservar2</a></i> ~;
}
$newshtml .= "</p>";
}
So I think it's one of the conditionals that I added that is causing the problem.
Thanks in advance ;)
[edited by: drewsuf at 10:36 pm (utc) on Jan. 22, 2003]
Be sure to read Marcia`s WebmasterWorld Welcome and Guide to the Basics [webmasterworld.com] post.
The function you posted works fine for me.
You might want to test the script from the command line with the -w switch to make the perl interpreter report warnings.
If you cannot figure out the problem yourself post the error messages you get.
Andreas
sub DoNewsHTML {[1]
if ($uservar1 ne "") {[2]
$newshtml .= qq~ <p><strong><a href="$uservar1" target="_blank">$newssubject</a> </strong><br><font size="2">Posted
$newsdate by <a href="mailto:$newsemail">$newsname</a><br> ~;
}[2]
$newshtml .= qq~ <p><strong>$newssubject</strong><br><font size="2">Posted
$newsdate by <a href="mailto:$newsemail">$newsname</a><br> ~;
}[1]
if ($uservar1 ne "") {[3]
$newshtml .= qq~ <img src="$uservar3" align="right" border="0"></a> ~;
}[3]
$newshtml .= "</p>";
}[no opening curly brace]
$newstext<br> ~;
if ($uservar1 ne "") {[4]
$newshtml .= qq~ <i>Source: <a href="$uservar1" target="_blank">$uservar2</a></i> ~;
}[4]]
$newshtml .= "</p>";
}[no opening curly brace] I suggest you use an editor that will show you matching braces and that uses code highlighting to avoid such errors in the future.
Have a look at the Editor forum at WebmasterWorld for some suggestions on nice text editors.
Andreas
I edited my post so you will see the faulty code now.
It would have been a good idea to post the new code in your new message. The editing feature is meant to allow you to correct spelling mistakes or other small glitches.
Changes that change the meaning of a message should be avoided and just posted as a new message. This will help other readers who do not know the editing history of a certain thread.
Andreas
I'm still not quite sure how the curly braces work. I guess they're like the >< commands in HTML. Could you please fix them for me? I'm not planning on using Perl very often, so I don't need an editor. I just need to customize this one setting for NewsPro.
Thanks a lot :)
I'm still not quite sure how the curly braces work.
In Perl curly braces are used to delimit a block of code. Blocks may be nested.
function
if(this)do this
if($uservar1) {
executed when $uservar1 is true, i.e. ne '';
executed when $uservar1 is true, i.e. ne '';
} This code is syntactically correct:
sub DoNewsHTML {
#
if ($uservar1) {
$newshtml .= qq~ <p><strong><a href="$uservar1"
target="_blank">$newssubject</a> </strong><br><font
size="2">Posted $newsdate by <a href="mailto:$newsemail"
>$newsname</a><br> ~;
} # end of if ($uservar1 ne "") {
#
# this is done unconditionally
$newshtml .= qq~ <p><strong>$newssubject</strong><br><font
size="2">Posted $newsdate by <a href="mailto:$newsemail"
>$newsname</a><br> ~;
#
if ($uservar1) {
$newshtml .= qq~ <img src="$uservar3" align="right"
border="0"></a> ~;
} # end of if ($uservar1 ne "") {
#
# this is done unconditionally
$newshtml .= "</p>";
$newstext<br> ~;
#
if ($uservar1) {
$newshtml .= qq~ <i>Source: <a href="$uservar1"
target="_blank">$uservar2</a></i> ~;
} # end of if ($uservar1 ne "") {
#
# this is done unconditionally
$newshtml .= "</p>";
} I do not know whether it will do what you want.
Andreas
Not sure what's wrong.
Thanks again. That description of conditionals helped my understanding of the code. I'm still a little shaky with syntax though.
$newshtml .= qq~$newstext<br>~; Note that qq~some string~; is just some fancy perl way of quoting the words "some string". In fact it is syntactically equivalent to those double quotes. But you do not have to escape double quotes when you want to use them within your string. So you can put the $newstext variable everywhere in your code between qq~ and ~.
Andreas
This is the code I'm using for my HTML output:
sub DoNewsHTML {
#
{
$newshtml .= qq~ <strong><a href="$uservar1"
target="_blank">$newssubject</a></strong><br><font
size="2">Posted $newsdate by <a href="mailto:$newsemail"
>$newsname</a><p> ~;
} # end of if ($uservar1 ne "")
#
if ($uservar3) {
$newshtml .= qq~ <a href="$uservar1" target="_blank"><img src="$uservar3" align="right"
border="0"></a> ~;
} # end of if ($uservar3 ne "") {
#
$newshtml .= qq~$newstext<br>~;
#
if ($uservar1) {
$newshtml .= qq~ <i>Source: <a href="$uservar1"
target="_blank">$uservar2</a></i></font> ~;
} # end of if ($uservar1 ne "") {
#
$newshtml .= qq~ <hr color="#ffffff" size="1" width="30%"><p> ~;
}
Is there anything in this code that could be causing the double posts? This is basically the only Perl setting I've messed around with, so I think it's either a problem with the program or with my coding.
Thanks again.
[edited by: jatar_k at 4:56 pm (utc) on Jan. 23, 2003]
[edit reason] no url's please [/edit]