in reply to Need a better way to break out a range of addresses...

Wow! I think I missed this one :(

Still, here is yet another alternative using Perl out of the box. No doubt, a master monk can probably shorten it even more.

use strict; use warnings; my @a = map { s/\s*(#.*)?$//g; $_ } <DATA>; my @b; while (local $_ = shift @a) { if (m/\D(\d+)-(\d+)(?:\D|$)/) { my $range = "$1-$2"; foreach my $i ($1..$2) { local $_ = $_; s/(\D)$range(\D|$)/$1$i$2/; push @a, $_; } } else { push @b, $_; } } print join("\n", @b); __END__ 172.17.119.2 # Comments are here... 172.17.119.4-5 # Comments are here... 172.19-21.254.2-3 # Comments are here... 192.168.1.1-3 # Comments are here...
Update: Slightly saner while loop using localized stack.
Update 2: Removed unnecessary localization of $1, $2. Thanks to ikegami++

Replies are listed 'Best First'.
Re^2: Need a better way to break out a range of addresses...
by RMaxwell (Novice) on Apr 02, 2007 at 19:45 UTC
    Hello,

    I used your solution and it worked like a charm!! Thanks for everyones help on this, there were a lot of cool solutions derived for my problem!

    Thanks,
    Robert Maxwell