Write an expression or perl script to identify the entered
ip address is valid or not?
Answer Posted / savitha sridhar
print "Enter an ip address: ";
$ans=<stdin>;
chomp($ans);
if ($ans =~ m/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
{
if (($1<=255) && ($2<=255) && ($3<=255) &&
($4<=255))
{
print "An IP Address";
}
else
{
print "Not an IP Address";
}
}
else
{
print "Not an IP Address";
}
Is This Answer Correct ? | 12 Yes | 1 No |
Post New Answer View All Answers
What are the two ways to get private values inside a subroutine?
Which guidelines by Perl modules must be followed?
How to connect to SQL server through Perl?
What is the purpose of “_file_ literal” and “_line_ literal” in perl?
What is a perl references?
Explain splicing of arrays?
How to read multi lines from a file in perl?
“Perl regular expressions match the longest string possible”. What is the name of this match?
How to renaming a file in perl programming?
Perl uses single or double quotes to surround a zero or more characters. Are the single(' ') or double quotes (" ") identical?
What is the use of –w?
How do you turn on the perl warnings?
What is the use of "stderr()"?
What does cgi program store?
What are the steps involved in configuring a server using cgi programming?