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
Differentiate between arrays and list in perl.
Explain the functioning of conditional structures in perl.
Why we use CGI?
Write a program to concatenate the $firststring and $secondstring and result of these strings should be separated by a single space.
Explain goto label?
What is confess function in perl?
What is a chomp() function in perl?
Can inheritance be used in perl? Explain with the help of an example.
What is subroutine in perl?
How to know whether a key exists or not in perl?
What is the difference between perl array and perl hash?
Why aren't Perl's patterns regular expressions?
How to read a file into a hash array?
There are two types of eval statements i.e. Eval expr and eval block. Explain them.
You want to download the contents of a url with perl. How would you do that?