Conditional statement to generate HTML?

E

Erica

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
 
M

Mohammad Mahmoud Khajah

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,
 
?

=?iso-8859-1?Q?Ren=E9?=

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
___ _ __
/ _ \___ ___ ___// __/ /
/ , _/ -_) _ \/ -_) |/ / /__
/_/|_|\__/_//_/\__/|___/____/
 
T

The Dead Bishop

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top