in reply to Need a better way to break out a range of addresses...
At first I thought something like Net::IP or NetAddr::IP could handle this, but apparently they don't. I would just write some regexps to pull this apart.
The following is pretty fragile in that it will fail to deal with bogus data like 10.11.12.30-29, but that should be easy enough to trap.
use strict; use warnings; while (<>) { chomp; s/\s*#.*$//; if (my ($stem, $first, $last) = /\b(\d+(?:\.\d+){2})\.(\d+)-(\d+)\ +b/) { print "$stem.$_\n" for $first..$last; } elsif (/\b(\d+(?:\.\d+){3})\b/) { print "$1\n"; } }
update: gah. I didn't initially spot that other octets apart from the last octet might have ranges in them. That means this solution is too simple-minded to be of much use.
• another intruder with the mooring in the heart of the Perl
|
|---|