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

How do I send e-mail from a Perl/CGI program on a Unix system?

595


How can arrays be tied?

525


What is lexical variable in perl?

529


You want to connect to sql server through perl. How would you do that?

550


what is the function that is used to identify how many characters are there in a string?

549






What are scalars in perl?

548


In CPAN module, name an instance you use.

550


How can memory be managed in Perl?

555


How to know whether a key exists or not in perl?

553


How to connect with sqlserver from perl and how to display database table info?

544


What are the advantages of programming in perl?

543


How can you create anonymous subroutines?

549


How do I replace every TAB character in a file with a comma?

558


How to convert strings into an array in perl?

523


Which functions in perl allows you to include a module file.

507