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 is perl language?
How to read a directory in perl?
Explain the functioning of conditional structures in perl.
What is the purpose of redo statement?
What is warn function in perl?
What is eval function in perl?
What does the’$_’ symbol mean?
How interpreter is used in perl?
Which functions in perl allows you to include a module file. State their differences.
Explain chomp, chop, cpan, tk.
What are scalar data and scalar variables?
Explain perl. When do you use perl for programming? What are the advantages of programming in perl?
what is Perl one liner?
What are the advantages of programming in perl?
How will you open a file in read-only mode in perl?