Code Comments
Programming Forum and web based access to our favorite programming groups.Hi,
How do I write the expression, if the variable match between 0 to 10? Below
is the wrong expression I wrote which is suppose to be if $eightdecks match
0 to 10. So i want the answer to be yes.
Thanks
my $eightdecks = 6;
if($eightdecks =~ /[0-10]/){
print "Yes match\n";
}else{print "no"};
Post Follow-up to this messagetry this one:
# perl -Mstrict -le 'my $x=shift; print 1 if $x=~/^[0-9]$|^10$/' 10
1
On 4/2/08, itshardtogetone@hotmail.com <itshardtogetone@hotmail.com> wrote:
> Hi,
> How do I write the expression, if the variable match between 0 to 10? Belo
w is the wrong expression I wrote which is suppose to be if $eightdecks matc
h 0 to 10. So i want the answer to be yes.
> Thanks
>
> my $eightdecks = 6;
>
> if($eightdecks =~ /[0-10]/){
> print "Yes match\n";
> }else{print "no"};
Post Follow-up to this messageHere is the code to match 0 to 10 using regex.
use warnings;
use strict;
print "Enter any number:";
my $input = <STDIN>;
chomp($input);
if($input=~ m/^10$|^[0-9]$/)
{
print "matched";
}
else
{
print "not matched";
}
Hope it helps.
-----Original Message-----
From: itshardtogetone@hotmail.com [mailto:itshardtogetone@hotmail.com]
Sent: Wednesday, April 02, 2008 2:09 PM
To: beginners@perl.org
Subject: how to write 0 to 10 in reg exp.
Hi,
How do I write the expression, if the variable match between 0 to 10? Below
is the wrong expression I wrote which is suppose to be if $eightdecks match
0 to 10. So i want the answer to be yes.
Thanks
my $eightdecks = 6;
if($eightdecks =~ /[0-10]/){
print "Yes match\n";
}else{print "no"};
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.