views:

165

answers:

1

I am trying to write a function which validates the username for an alphanumeric value and in the case of failure it should log my custom error message and return 0 to the called function instead of die-ing:

sub insertUser{
            my ( $username, $password, $email, $name) = validate_pos( @_, 
                   { type => SCALAR,
                     regex => qr/^\w+$/,
                     on_fail => { $err->error("username validation failed"),return 0 }  
                     },
                    { type => SCALAR },
                    { type => SCALAR },
                    { type => SCALAR ,optional => 1,default => 99});
            print "$username, $password, $email, $name ";
}

With the above code I am facing a problem like it's still returning 0 in the success case. Can anybody please help me in this regard and could anyone explain me why it is doing so?

+1  A: 
molecules
firstly thanks for your response,could you tell that ,"is there any way it returns a value 0" in the case of failure instead of "die" in insert user funtion. Thanks in advance
Fedrick