HarshaHegde has asked for the wisdom of the Perl Monks concerning the following question:
I have a piece of code which checks if a string is an IP Address or not and prints a 1 if the string is a valid IP and 0 otherwise.
If the ip is valid, this piece of code prints:#!/usr/bin/perl use strict; use warnings; main(); exit; ############################################### sub main { my $ip = qq{127.0.0.1}; print "IP Validity Status:". validate_ip_addr($ip),$/; } sub validate_ip_addr { my ($addr_to_check) = shift; return ( $addr_to_check =~ m/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ + ); }
However, if the IP is invalid, what I see is:IP Validity Status:1
How do I make it print:IP Validity Status:
?IP Validity Status:0
TIA,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: printing true false values
by McDarren (Abbot) on Dec 30, 2007 at 16:06 UTC | |
by HarshaHegde (Sexton) on Dec 30, 2007 at 16:11 UTC | |
|
Re: printing true false values
by jasonk (Parson) on Dec 30, 2007 at 15:51 UTC | |
by HarshaHegde (Sexton) on Dec 30, 2007 at 16:15 UTC | |
by tinita (Parson) on Dec 30, 2007 at 16:43 UTC | |
by Somni (Friar) on Dec 30, 2007 at 16:26 UTC | |
by bobf (Monsignor) on Dec 31, 2007 at 02:26 UTC | |
by Anonymous Monk on Dec 31, 2007 at 14:18 UTC | |
|
Re: printing true false values
by jwkrahn (Abbot) on Dec 30, 2007 at 16:05 UTC | |
|
Re: printing true false values
by FunkyMonk (Bishop) on Dec 30, 2007 at 15:52 UTC | |
|
Re: printing true false values
by ysth (Canon) on Dec 30, 2007 at 23:49 UTC |