On Mon, 03 Mar 2003 18:50:35 +0000, Anadi Taylor wrote:

> OK - here is the thing: I have written some code and it works fine 
> (yahoooo), but i was wondering if there is a more 'PERL' way of doing things 
> as this code looks bulky to me !!!!
> 
> the code id:
> 
> ## check to see if username or email already exist
> 
>       $errmesseml     = "False";
>       $errmessuser    = "False";
>       $emailuserfound = "False";
> 
>       if($dbemail eq $email)
>       {
>               $errmesseml = "True";
>       }
> 
>       if($dbusername eq $membusrname)
>       {
>               $errmessuser = "True";
>       }
> 
> ## create readable error message
> 
>       $errmessage = "";
> 
>       if (($errmesseml eq "True") and ($errmessuser eq "True"))
>       {
>               $errmessage = "Both the email address and the username have already 
> been 
> used";
>               $emailuserfound = "True";
> 
>       }

First you could use the Perl conventions to express True and False.
True is everything that is non zero, non-empty or similar.
Especially, every comparison returns such a boolean value.

my $errmessage;

my $errmesseml     = $dbmail     eq $mail;
my $errmessuser    = $dbusername eq $membusrname;
my $emailuserfound = $errmesseml || $errmessuser;  # if I understand the
                                                   # logic right

Then we can set the errmessage in a more elegant way:

my $errmessage;
if ($errmessem1 && $errmessuser) { 
   $errmessage = 
        "Both the email address and the username have alread been used";
} 
elsif ($errmesseml) {  # $errmessuer can't be true yet
   $errmessage = "The email address has already been used";
}
elsif ($errmessuser) {
   $errmessage = "The username has already been used";
}   

You could express it more short with the ?: operator style.
If you're interested in, just read 
perldoc perlop
 
> I have tried to use lines like:
> 
> if ($errmesseml and !($errmessuser)) { do something }
> 

> but it doesnt work !!!! A bit of a bummer really - any ideas ?????

The reason is that for Perl the strings
"True" and "False" are both true values!


Greetings,
Janek


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to