On Mon, 28 Feb 2005 10:07:49 +0000, Graeme McLaren <[EMAIL PROTECTED]> wrote: > Morning all. I have a strange problem with an if-else statement. Both > parts of the statement are being executed and I have no idea why, the > offending code is this: > > if($password =~ /\S\S\d\d\S\S/){ > #if there is a password user then exists in ldap, update the > username > $error = ChangeUsername($old_username, $new_username, 'suppliers', > 'select', 'dci'); > # make sure user has "approved" status > record_username_success([EMAIL PROTECTED], $count); > print "username changed from \"$old_username\" to > \"$new_username\" using password \"$password\" \n"; > }else{ > handle_error($error, [EMAIL PROTECTED], $count); > } > > It prints off the username that has been changed and its password. Then the > handle_error function is called. > > Anyone got any ideas? > > Cheers in advance, > > Graeme :) > > --
Graeme, We need a little more code here, or at least some more information: First, where is handle_error declared? Do you declare handle_error inside the loop that contains the if block? Since you're not calling it with &, you must be predeclaring it, and it might be reusing some variables in way you aren''t expecting. More imporatntly, you haven't scoped $error properly. It remains set, and will trigger whatever tests you have for it. Until you unset it. Where else are you setting it and tersting fo it? Obviously, you expect it to be set in the else block to call handle_error on it; how is that assignment happening? Probably when the else block executes, it's using $error from the last successful execution of the if block. This script here is exactly whay people constant advise using strict and warnings in all programs, Turn them on, get your variables properly scoped and your problems will find themselves. --jay -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>