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 is perl shift array function?

745


How to read file into hash array ?

815


What does Perl do if you try to exploit the execve(2) race involving setuid scripts?

747


Write a program to show the process of spawning a child process

658


Distinguish my and local?

745


What rules must be followed by modules in perl.

763


What is perl pop array function?

732


How will you open a file in a write-only mode in perl?

735


How many types of variable in perl?

805


How can I implement the function overloading in Perl ? I read about the operator overloading, I do not know how to implement the function overloading. Thanks in advance ?

2696


What is the difference between perl list and perl array?

668


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

764


explain the various functions/directives in perl that allow you to include/import a module. Also, state the differences between them.

665


What are the logical operators used for small scale operations? Explain them briefly.

745


What does read () command do?

709