Anadi Taylor wrote: > Hi all, > I have to start by thanking you all for your help so far - its been > invaluable. If it were'nt for you guys and gals i would have pulled > my hair out by now !!!!! > > 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"; > }
Most programmers would prefer to see you use Perl's concept of true and false. Basically, anything that evaulates to an empty string "", or a single zero "0" is false, and everything else is true. So, you could write: my ($errmesseml, $errmessuser, $emailuserfound); # all get set to undef (false) $errmesseml = $dbemail eq $email; > > if($dbusername eq $membusrname) > { > $errmessuser = "True"; > } $errmessuser = $dbusername eq $membusrname; > > ## create readable error message > > $errmessage = ""; my $errmessage; > > if (($errmesseml eq "True") and ($errmessuser eq "True")) { > $errmessage = "Both the email address and the > username have already been > used"; > $emailuserfound = "True"; > > } > > if (($errmesseml eq "True") and ($errmessuser ne "True")) { > $errmessage = "The email address has already been used"; > $emailuserfound = "True"; } > > if (($errmesseml ne "True") and ($errmessuser eq "True")) { > $errmessage = "The username has already been used"; > $emailuserfound = "True"; } It looks like you want $emailuserfound to be true if one or both of $errmesseml or $errmessuser is true. So that is simply: $emailuserfound = $errmesseml || $errmessuser; Then you're setting an error message based on one of three mutually exclusive tests. You can write this as: if ($errmesseml && $errmessuser) { $errmessage = "Both the email address and the username have already been used; } elsif ($errmesseml) { $errmessage = "The email address has already been used"; } elsif ($errmessuser) { $errmessage = "The username has already been used"; } But looking at the overall logic, I think you can simplify further and get rid of the intermediate variables. $emailuserfound seems to be redundant. It's true if there's something in $errmessage and false if not. So why not just use $errmessage. Also, I think you could get rid of the $errmesseml and $errmessuser flags, unless you need those somewhere else in the code. How about this: my $errmessage; if ($dbemail eq $email && $dbusername eq $membusrname) { $errmessage = "Both the email address and the username have already been used"; } elsif ($dbemail eq $email) { $errmessage = "The email address has already been used"; } elseif ($dbusername eq $membusrname) { $errmessage = "The username has already been used"; } > > > > I have tried to use lines like: > > if ($errmesseml and !($errmessuser)) { do something } Because Perl is treating your strings "True" and "False" as both true. > > but it doesnt work !!!! A bit of a bummer really - any ideas ????? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]