Bruce Ferrell <bferr...@baywinds.org> wrote:
>  if ( ! defined $username || ! $username =~ /[0-9]{10,11}/ ) {
> 
> do something;
> 
> } else {
> 
> do something else;
> 
> }
> 
> what that's supposed to do is this:
> if it's blank or not 10 or 11 digits...
> 
> The question is where is my understanding faulty or did I mess up.

defined() is true if the checked variable has been assigned any value except 
undef, so defined $username will be true for an empty username, too.

In any case I'd probably rather write your code like this:

        $username ||= ''; # make sure it's always defined

        unless( $username =~ m/^\d{10,11}$/ ){
          # bad username
        } else {
          # good username
        }

HTH,
Thomas

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to