Question on "if" statement

H

Huub

Hi,

I have a script that somehow doesn't process the "if" statement.

$plaats = "select plaats from hvw where lidnr = $record";
$sth = $dbh->prepare($plaats);
$sth->execute or die "SQL Error: $DBI::errstr\n";
@plaats = $sth->fetchrow_array;
$plaats[0] = @plaats;
if ($plaats[0] == 'Londen')
{
$voorletters = "select voorletters from hvw where lidnr = $record";
$sth = $dbh->prepare($voorletters);
$sth->execute or die "SQL Error: $DBI::errstr\n";
@voorletters = $sth->fetchrow_array;

This script stays busy without result.

$plaats = "select plaats from hvw where lidnr = $record";
$sth = $dbh->prepare($plaats);
$sth->execute or die "SQL Error: $DBI::errstr\n";
@plaats = $sth->fetchrow_array;
$plaats[0] = @plaats;
unless ($plaats[0] == 'Londen')
{
$voorletters = "select voorletters from hvw where lidnr = $record";
$sth = $dbh->prepare($voorletters);
$sth->execute or die "SQL Error: $DBI::errstr\n";
@voorletters = $sth->fetchrow_array;

Though this does give results, it shows everything, including when it's
Londen.

I've been searching through CPAN and have tried with and without
brackets and/or quotes, @ instead of $, with and without [0], but I
can't get it right. Where am I going wrong?

Thanks for helping out.

Huub
 
P

Paul Lalli

Huub said:
I have a script that somehow doesn't process the "if" statement.

$plaats = "select plaats from hvw where lidnr = $record";
$sth = $dbh->prepare($plaats);
$sth->execute or die "SQL Error: $DBI::errstr\n";
@plaats = $sth->fetchrow_array;
$plaats[0] = @plaats;

What, exactly, do you think that line is doing?
if ($plaats[0] == 'Londen')

You are not running with warnings enabled. It's extremely rude of you
to ask hundreds of people around the world to tell you what you've done
wrong, when you haven't even bothered to ask Perl what you've done
wrong.

Put the line:
use warnings;
at the top of your script, right under the shebang.

When Perl gives you the warning about this line, if you can't figure
out what it means, first read:
perldoc perldiag
If you can't figure it out from there, read some introductory Perl
documentation:
perldoc perlintro
perldoc perldata
perldoc perlsyn
perldoc perlop

If you still don't get it, post here again. Make sure the code you
post has both 'use strict;' and 'use warnings;' enabled.

Paul Lalli
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top