On Dec 3, 2007 1:16 PM, sivasakthi <[EMAIL PROTECTED]> wrote: > Hi all, > > I have tried to find the entered number is single digit or not.. > > the code is following, > > #! /usrbin/perl > use strict; > use warnings; > > my $tmp=<STDIN>; > if($tmp =~ m/(\d)/) > { > print"NO IS SINGLE DIGIT\n"; > } > else > { > print"NO IS NOT SINGLE DIGIT\n"; > } > > > > but it always passed the condition even if we entered the more no of > digit numbers?? >
Try this improvment code: #! /usrbin/perl use strict; use warnings; my $tmp=<STDIN>; chomp $tmp; # though it's not needed chomp it here, but you'd better to do this. if($tmp =~ /^\d{1}$/) { print"IT IS SINGLE DIGIT\n"; } else{ print"IT IS NOT SINGLE DIGIT\n"; } -- Jeff (yonghua) Pang MailSys and Antispam with Perl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/