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 does this symbol mean '->'?
What is the difference between localtime() and gmtime() functions?
What are the advantages of programming in perl?
How to close a file in perl?
For a situation in programming, how can you determine that Perl is a suitable?
How do you you check the return code of a command in perl?
There is no strict data types in perl unlike in other high level languages like Java so wouldn't that be a problem if a code in perl is to be a written by a big team of 20+ members ?"
Explain a tell function in perl?
How can you create anonymous subroutines?
How can I display all array element in which each element will display on next line in perl ?
Write syntax to add two arrays together in perl?
What does Perl do if you try to exploit the execve(2) race involving setuid scripts?
How to remove a directory in perl?
Why Perl aliases are considered to be faster than references?
How does polymorphism work in perl? Give an example.