By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,294 Members | 2,645 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,294 IT Pros & Developers. It's quick & easy.

Conditional statement to generate HTML?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.