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
How can you call a subroutine and identify a subroutine?
Explain what is STDIN, STDOUT and STDERR?
Which functions in Perl allows you to include a module file or a module and what is the difference between them?
You want to print the contents of an entire array. How would you do that?
Where do we require ‘chomp’ and what does it mean?
How will you get the count of parameters passed to a perl subroutine?
What is grep used for in perl?
how to extract pin_code,phone_number,year from text file using regular expressions in perl
How many ways can we express string in Perl?
Explain a tell function in perl?
Write a program that explains the symbolic table clearly.
What is the difference between perl array and perl hash?
Perl regular expressions are greedy" what does this mean?
what are steps to do to lock the sony ericsson mobile with password?
what is the main function of fork() in cgi programming?