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

Explain goto label?

517


Explain tk?

519


What does -> symbol indicates in Perl?

569


Explain the functioning of conditional structures in perl.

468


What is the use of -t?

548






What are the steps involved in configuring a server using cgi programming?

481


What happens when you return a reference to a private variable?

534


What is the difference between use and require in perl programming?

516


Explain the arguments for perl interpreter.

528


What are the two ways to get private values inside a subroutine?

454


How to print escaping characters inside a string in perl?

513


What is confess function in perl?

544


How will you create a file in perl?

523


How to replace perl array elements?

529


What is the function of cgiwrap in cgi programming?

494