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


Please Help Members By Posting Answers For Below Questions

What are the two ways to get private values inside a subroutine?

446


Which guidelines by Perl modules must be followed?

564


How to connect to SQL server through Perl?

556


What is the purpose of “_file_ literal” and “_line_ literal” in perl?

529


What is a perl references?

516






Explain splicing of arrays?

510


How to read multi lines from a file in perl?

497


“Perl regular expressions match the longest string possible”. What is the name of this match?

520


How to renaming a file in perl programming?

537


Perl uses single or double quotes to surround a zero or more characters. Are the single(' ') or double quotes (" ") identical?

515


What is the use of –w?

525


How do you turn on the perl warnings?

490


What is the use of "stderr()"?

565


What does cgi program store?

531


What are the steps involved in configuring a server using cgi programming?

476