470,810 Members | 885 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

Conditional statement to generate HTML?

Hi,

I'm an experienced programmer, but very new at perl, so please excuse
my newbishness :)

I am trying to modify an existing piece of perl code for an online
store that sells movies. Some of the videos in the inventory are now
available in DVD, so I want to add a DVD checkbox option for the
appropriate movies.

There is a boolean field in the database that is set to 1 if it is
available in DVD. Ideally, what I would like is an if-statement that
generates a piece of HTML if the boolean is true. However, it doesn't
seem that this can be done. Does anyone know how this could be
accomplished? I'm really at my wits end...

Thanks so much in advance!!
--Erica
Jul 19 '05 #1
3 5466
On Thu, 15 Jul 2004 21:52:36 -0700, Erica wrote:
Hi,

I'm an experienced programmer, but very new at perl, so please excuse
my newbishness :)

I am trying to modify an existing piece of perl code for an online
store that sells movies. Some of the videos in the inventory are now
available in DVD, so I want to add a DVD checkbox option for the
appropriate movies.

There is a boolean field in the database that is set to 1 if it is
available in DVD. Ideally, what I would like is an if-statement that
generates a piece of HTML if the boolean is true. However, it doesn't
seem that this can be done. Does anyone know how this could be
accomplished? I'm really at my wits end...

Thanks so much in advance!!
--Erica


Hi,

You need to investigate the code that fetchs the records from the database
and then you can add an C<if> conditional for your boolean value.

Example:
Suppose your DB looked like this:
id|^|movie's name|^|bool DVD

Now, you can have the following piece of code to generate your HTML:
open(FILE, 'your database file') or die($!);
flock(FILE, LOCK_SH);
while(<FILE>) {
chomp($_);
my @line = split(/\|\^\|/, $_);

# column #3 is your boolean value, so we test for it here
if ( $line[2] == 1 ) {
print "your html ...";
}
}
close(FILE);

The procedure is smiliar for a RDBMS like MySQL.

Good luck,

Jul 19 '05 #2
In article <34**************************@posting.google.com >, Erica wrote:
Hi,

I'm an experienced programmer, but very new at perl, so please excuse
my newbishness :)

available in DVD. Ideally, what I would like is an if-statement that
generates a piece of HTML if the boolean is true. However, it doesn't
seem that this can be done. Does anyone know how this could be
accomplished? I'm really at my wits end...


Of course it can be done:
if ($field == 1){ print "<html>...</html>";}
The exact implementation depends on your code, which you have not included.
--
{groeten|regards}, René van Leeuwen
___ _ __
/ _ \___ ___ ___// __/ /
/ , _/ -_) _ \/ -_) |/ / /__
/_/|_|\__/_//_/\__/|___/____/

Jul 19 '05 #3
Following Renees remarks, maybe the confusion is due to the fact
that Perl basically does not have explicit Boolean vars like
other programming languages do. The syntax for allmost all
vars is the same, Perl will determine the var type automatically.
On Thu, 15 Jul 2004 21:52:36 -0700, Erica wrote:
Hi,

I'm an experienced programmer, but very new at perl, so please excuse
my newbishness :)

I am trying to modify an existing piece of perl code for an online
store that sells movies. Some of the videos in the inventory are now
available in DVD, so I want to add a DVD checkbox option for the
appropriate movies.

There is a boolean field in the database that is set to 1 if it is
available in DVD. Ideally, what I would like is an if-statement that
generates a piece of HTML if the boolean is true. However, it doesn't
seem that this can be done. Does anyone know how this could be
accomplished? I'm really at my wits end...

Thanks so much in advance!!
--Erica


Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Benjamin Niemann | last post: by
7 posts views Thread by Shaldaman | last post: by
92 posts views Thread by Raghavendra R A V, CSS India | last post: by
2 posts views Thread by estafford | last post: by
37 posts views Thread by Steven Bethard | last post: by
18 posts views Thread by Steven Bethard | last post: by
5 posts views Thread by paulo | last post: by
11 posts views Thread by Ciaran | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.