Write an expression or perl script to identify the entered
ip address is valid or not?
Answer Posted / anil
The first reply won't match 192.168.99.99. [0-5] matches
only 0,1,2,3,4,5. How about the other numbers?
Second one is almost correct, but the first octet can't be
'0'. I mean, 0.1.2.3 is not a valid address.
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>0) && ($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 ? | 2 Yes | 1 No |
Post New Answer View All Answers
What are the arguements we normally use for perl interpreter?
List the prefix dereferencer in Perl.
In Perl we can show the warnings using some options in order to reduce or avoid the errors. What are that options?
What are the different instances used in cgi overhead?
How will you create a file in perl?
What is the use of 'ne' operator?
How to close a directory in perl?
What is hash?
How many data types are there in perl?
How to convert arrays into a string in perl?
Explain lexical variables.
Mention the difference between die and exit in Perl?
explain the various functions/directives in perl that allow you to include/import a module. Also, state the differences between them.
How can you use Perl warnings and what is the importance to use them?
what are steps to do to lock the sony ericsson mobile with password?