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
Explain about typeglobs?
Explain the difference between "my" and "local" variable scope declarations. ?
What interface used in PERL to connect to database? How do you connect to database in Perl?
you are required to replace a char in a string and store the number of replacements. How would you do that?
What is subroutine in perl?
What is the use of -w, -t and strict in Perl?
Explain substr function in perl?
What is the use of -n and -p options?
Explain join function in perl?
How to determine strings length in perl?
Which functions in perl allows you to include a module file. State their differences.
How can we create perl programs in unix, windows nt, macintosh and os/2 ?
What is the use of command “use strict”?
What does delete function do in perl?
how to connect cisco switch uisng perl script