Ask and ye shall receive :)  The most recent solution is the first on the list.

Benchmark: timing 10000 iterations of use_grep_block, use_map_split, use_regex, 
use_rindex, use_split...
use_grep_block:  8 wallclock secs ( 7.96 usr +  0.00 sys =  7.96 CPU) @ 1256.12/s 
(n=10000)
use_map_split: 10 wallclock secs ( 9.94 usr +  0.01 sys =  9.95 CPU) @ 1004.62/s 
(n=10000)
 use_regex:  6 wallclock secs ( 6.14 usr +  0.00 sys =  6.14 CPU) @ 1628.93/s (n=10000)
use_rindex:  4 wallclock secs ( 4.04 usr +  0.00 sys =  4.04 CPU) @ 2477.70/s (n=10000)
 use_split: 10 wallclock secs ( 9.20 usr +  0.00 sys =  9.20 CPU) @ 1086.60/s (n=10000)


Peter Guzis
Web Administrator, Sr.
ENCAD, Inc.
- A Kodak Company
email: [EMAIL PROTECTED]
www.encad.com 

-----Original Message-----
From: Rob Dixon [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 23, 2004 5:37 AM
To: Matt Bazan; [EMAIL PROTECTED]
Subject: Re: Need help pruning data..


Matt Bazan wrote:
>
> I've got an array that contains several dozen IP addresses
> (along with a bunch of garbage output from running the NMAP command).  I
> want to find the fastest, cleanest way to remove all IP address who's
> last octet is 10 or below and all IP addresses who's last octet is 200
> or higher.  I can think of several ways to do this by using reg ex's and
> looping through the data but am wondering if there is a faster way, or,
> if not, if a cleaner way than what I've come up with:
> 
> my $bad_ip;
> my @results = `c:/perl/nmap/nmap.exe -sP -n $Subnet`; #subnet is a /24
> private IP block
> foreach (@results) { 
> if (/(\d+\.\d+\.\d+\.(\d+))/ { #match on IP addresses only
> if ($2 =~ <reg ex to match numbers 10 or below> or
> <regex to match numbers 200 or greater>) {
> next;
> }
> else {
> ..do something..
> }
> }
> } 

Hi Matt.

Will this do? Peter could benchmark it with the data he used so that you can
compare the speeds, but I doubt if there's much to choose between the solution
in real terms.

HTH,

Rob




chomp (my @results = <DATA>);

my @pruned = grep { /^\d+\.\d+\.\d+\.(\d+)$/ and $1 > 10 && $1 < 200 } @results;

print map "$_\n", @pruned;

__DATA__
1.2.3.4
5.6.7.8
9.10.11.12
13.14.15.16
17.18.19.20
AA.22.23.24
25.26.BB.28
29.30.31.CC
45.46.47.48
100.101.102.103
190.191.192.193
196.197.198.199
200.201.202.203
204.205.206.207

**OUTPUT

9.10.11.12
13.14.15.16
17.18.19.20
45.46.47.48
100.101.102.103
190.191.192.193
196.197.198.199

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to