WOW!!! Still to see the world... Thanks :)

On Mon, Apr 9, 2012 at 4:04 AM, John W. Krahn <jwkr...@shaw.ca> wrote:

> Somu wrote:
>
>> Hello everyone...
>>
>
> Hello,
>
>
>  Thanks for the previous replies. I'm really improving!
>> A new problem..
>>
>> Check if the word begins with un or in and has exactly 5 letters.
>> $word =~ '^(un|in).{3}$'
>>
>
> You should use the matching operator on the right hand side of the binding
> operator instead of a string, so either:
>
> $word =~ m'^(un|in).{3}$';
>
> If you don't want interpolation, or:
>
> $word =~ /^(un|in).{3}$/;
>
> You are using capturing parentheses, which may, or may not be required,
> but you would normally use non-capturing parentheses:
>
> $word =~ /^(?:un|in).{3}$/;
>
> Or because there is only one letter difference it would be better to use a
> character class:
>
> $word =~ /^[ui]n.{3}$/;
>
> Also, the use of . will match more than just letters.  If you want the
> string to only contain letters then:
>
> $word =~ /^[ui]n[[:alpha:]]{3}$/;
>
> And finally, the use of the $ anchor implies that the string could end
> with an optional newline.  If you want to ensure that there is no newline
> present then:
>
> $word =~ /\A[ui]n[[:alpha:]]{3}\z/;
>
>
>
> John
> -- *
> Any intelligent fool can make things bigger and
> more complex... It takes a touch of genius -
> and a lot of courage to move in the opposite
> direction.                   -- Albert Einstein*
>
> --
> 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