in reply to Parsing IPv4 Addresses and distinguishing Masks
because else you mean "any one to three digits followed by any sign", which might not be what you have in mind. but now to your questions:/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
2) How to distinguish subnet masks from IP address.my $ip; if ($line =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/ && $1 <= 255 && $2 <= 255 && $3 <= 255 && $4 <= 255) { $ip = "$1.$2.$3.$4"; }
my ($ip, $subnet); if ($line =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/ && $1 <= 255 && $2 <= 255 && $3 <= 255 && $4 <= 255) { $ip = "$1.$2.$3.$4"; $subnet = 1 if $1 == 255; }
|
|---|