Write an expression or perl script to identify the entered
ip address is valid or not?

Answer Posted / snehal kashikar

#! /usr/bin/per
use strict;
#- Use Input
#---------------
my $ip_add = "";

#- Script start
#---------------
print"Enter the IP address\n";
$ip_add = <STDIN>;
chomp($ip_add); # Remove the last "\n" character
$ip_add=$ip_add."\."; # Append . at the end of IP address
#-------Expression to check IP address is valid or not-----#
if($ip_add =~ m/^[0-2]?[0-5]?[0-5]?\.){4}$){
print" Valid IP Address\n";
}else{
print" Invalid IP Address\n"
}

Is This Answer Correct ?    1 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does last statement do in perl?

761


Explain string comparison operators in perl.

774


How does polymorphism work in perl?

689


Which guidelines by Perl modules must be followed?

781


What is the function of cgiwrap in cgi programming?

657


What's the difference between /^Foo/s and /^Foo/?

774


How will you access an element of a perl array?

702


What are the reasons that cookie server can’t handle multiple connections?

739


what is Chop & Chomp function does?

773


Explain goto label?

719


Perl regular expressions are greedy" what does this mean?

675


What is an interpolation in perl?

757


List the files in current directory sorted by size ?

682


What are scalars?

759


Mention how many ways you can express string in Perl?

799