Answer to question 1
#logic we are retrieving the value after the second (.) and third (.) and checking if they are in the range or not
# $1 = first value match in the pattern match which is there in first parenthesis (d)+
# $2 = second value match in the pattern match which is there in second parenthesis (d)+
Code
/home/gkhurana> perl
if($ip =~ m/172.125.(d+).(d+)/)
{
if ($1 >=1 and $1 <=25 and $2 >=0 and $2 <=255 )
{
IP address is within the range
" ;
}
else
{
IP address is out of the range
";
}
}
172.125.1.20
IP address is within the range
/home/gkhurana>
Login to rate this answer.
First we are searching for a vowel , if its found we are removing it from the string
example if input string $in=hello, then since vowels are present in it , we are removing them
so $in=hll (removed all vowels) , now we know there were vowels present in the input
now we are making sure that rest string should have atleast 3 non vowel characters
Code
print "Please enter the input(0 to exit) :- ";
if ($in=~ s/[aeiou]+//gi and $in=~/[b-df-hj-np-tv-z]{3,}/ig)
{
It contains a vowel and atleast 3 characters which are not vowels .
";
}
else
{
It does not meet the requirements
";
}
Login to rate this answer.
answer to question 3:
Validated the general email id that we use but not all validation as suggested on
http://en.wikipedia.org/wiki/Email_address
Code
/home/gkhurana> perl
@input=(a@gmail.com,a@a.ca,bcfdd.com,abc@a.in,aaaaaaaaaaaaaaaaa@a.,abcasbcscdb@A.com,abc1234@yahoo.com,abc1234abc@yahoo.co.in,1234@yahoo.com,sachin.te@yahoo.com);
foreach $in (@input)
{
# first matching should start with character then . or _ and then numbers and then @ symbol after that yahoo.com or it could be yahoo.co.in
# assuming that atleast 2 character should come after .
if ($in=~/^ [a-z]+ .? \_? [0-9]* [a-z]* @ [a-z]+ .[a-z]{2,} .?([a-z]{2,})?$ /ix)
{
$in is a correct email id
";
}
else
{
$in is not a correct email id
";
}
}
^D
a@gmail.com is a correct email id
a@a.ca is a correct email id
bcfdd.com is not a correct email id
abc@a.in is a correct email id
aaaaaaaaaaaaaaaaa@a. is not a correct email id
abcasbcscdb@A.com is a correct email id
abc1234@yahoo.com is a correct email id
abc1234abc@yahoo.co.in is a correct email id
1234@yahoo.com is not a correct email id
sachin.te@yahoo.com is a correct email id
/home/gkhurana>
Login to rate this answer.