"Anadi Taylor" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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:
use strict; > ## check to see if username or email already exist > # dont need this > $errmesseml = "False"; > $errmessuser = "False"; > $emailuserfound = "False"; > if($dbemail eq $email) > { > $errmesseml = "True"; > } my($emailFlag) = ($dbemail eq $email) ? 1 : 0; > if($dbusername eq $membusrname) > { > $errmessuser = "True"; > } my($userFlag) = ($dbusername eq $membusrname) ? 1 : 0; > ## 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"; > > } > > 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"; > } > my($errorMessage) = ''; if ( $emailFlag and $userFlag ) { # they are both in the database $errorMessage = "Both the email address and the username have already been used"; } elsif ( $emailFlag ) { # email address is in the database $errorMessage = "The email address has already been used"; } elsif ( $userFlag ) { # username is in the database $errorMessage = "The username has already been used"; } you also will not need the $emailuserfound variable. Just use $errorMessage and check its truth: print('The uid/pwd are not in the database') unless ( $errorMessage ); # same as if ( ! $errorMessage ) JFYI, with perl, ( sometimes ) the most perlish way of doing something is the way a given individual can write working code in the shortest amount of time. Since your code looks like it does what you wanted it to do, except for the obvious absence of use strict, I'd call it the 'most perlish' way for you to get the job done at that point in time. But I understand that you were looking for examples at how others would write the code. HTH, Todd W. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]