> > I have a number $page = 500; > now i want to check that if $page matches a word character then make $page > =1;
$page = 1 unless ( $page =~ /\d/ ); or $page = 1 if ($page =~ /\D/ ); > so originally i did this > my $page =500; > if(($page =~ /\w/) || ($page <= 0)){ > $page=1; > } > print"$page"; \w means [a-zA-Z0-9], "5" is one of them. > > since it always returns $page = 1; then i did this > if(($page =~ /(\w)/) || ($page <= 0)){ > $page=$1; > } > so it displayed the word 5, how come 5 is considered as a word?? Since in string "500", the regex catch "5" as a word at the very first, and the regex action is ended and so $1 carries "5". You then assing $page = $1, so $page = "5"; > so to fix it i just did > if(($page =~ /(\D)/) || ($page <= 0)){ > $page=$1; > } > And everything worked ok!! It doesn't ok... since \D means [^0-9], so the block doesn't run at all, so $page still = 500.... So, if $page = "END", then, you will fine $page = "E" after this block. Note : The $DIGIT means the sequence for results from catching matched pattern in the blankets you assigned. It means, $1 is the first match , $2 is the second match, and so on... $page = 500; $page =~ /(\d)(\d)(\d)/; $page = $3 . $1; print $page ; # you got 05, the last and first digit... HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]