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

You want to add two arrays together. How would you do that?

487


What is use of ‘->’ symbol?

537


How to read a single line from a file in perl?

546


How to read a file into a hash array?

548


Explain string comparison operators in perl.

555






What does the q{ } operator do?

517


What $! In perl?

527


How do you give functions private variables that retain their values between calls?

565


What is the main function of cookie server?

529


How many types of variable in perl?

554


What is the usage of -i and 0s options?

548


Remove the duplicate data from @array=(“perl”,”php”,”perl”,”asp”)

620


What are the logical operators used for small scale operations? Explain them briefly.

547


What rules must be followed by modules in perl.

571


Which operator in perl is used for the concatenation of two strings?

498