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
Which of these is a difference between Perl and C++ ?
Explain arrays in perl.
What is a chomp() function in perl?
How will you create a file in perl?
Write a program to decode the data in the form using cgi programming
How many data types are there in perl?
Explain the meaning of perl one-liner?
What is goto statement in perl?
How to connect to SQL server through Perl?
Which has highest precedence in between list and terms? Explain?
What is perl push array function?
What is the difference between die and exit in perl?
What happens to objects lost in "unreachable" memory, such as the object returned by Ob->new() in `{ my $ap; $ap = [ Ob->new(), $ap ]; }' ?
You want to open and read data files with perl. How would you do that?
Explain the difference between declarations of 'my' and 'local' variable scope in perl?