Basically, I wanted to store all private class A IP addresses in an array so I can perform network test with them. That is about 16 Million entries. On a computer that has 1 G of memory it will hog up 800M in no time. The worst part is that it can't finish storing them. What is the best approach to fix the problem? Thanks in advance.Tony --
I'm no expert, so I feel out on a limb (as it were), but I played around with this a bit and came up with a couple of rough scripts. I ran the first one on (0..1) in just a couple of minutes. It gave me a 5 meg file. It never uses much ram.
If nothing else, this may inspire you to find a good solution. If I'm totally clueless, then perhaps someone will enlighten us both. ;-)
-- mike higgins
#make ip range-- - -- - - -- - - -- - -
use MLDBM qw(DB_File Storable); use Fcntl; use strict;
my %o;
my $dbm = tie %o, 'MLDBM', 'ip_file', O_CREAT|O_RDWR, 0640 or die $!;
keys %o = 6581375;
#10.0.0.0 through 10.255.255.255 print 'start: '.(scalar localtime time)."\n"; my $it = 0;
my $string = '0a';
foreach (0..255){
my $string2 = $string . sprintf "%02x", $_;
foreach (0..255){
my $string3 = $string2 . sprintf "%02x", $_;
foreach(0..255){
my $string4 = $string3 . sprintf "%02x", $_;
$o{ $string4 } = $it++;
}
}
}print 'end: '.(scalar localtime time)."\n";
- - --- -- - -- - -- -
# read data - - -- - -- - --
use MLDBM qw(DB_File Storable); use Fcntl; use strict;
my %o; my $dbm = tie %o, 'MLDBM', 'ip_file', O_RDWR, 0640 or die $!;
=pod # this works on the smaller file, to dump it in order. # can't imagine this working on the whole thing...
foreach my $key (
map {$_ ->[0]} sort {$a->[1] <=> $b->[1]}
map{ [($_, $o{$_})]} keys %o )
{
print join '.', map {hex unpack ("x$_ a2", $key )} (0,2,4,6);
print "\n";
}=cut
my $ip = '10.0.0.255';
$ip = join '', map{ sprintf "%02x",$_} split /\./,$ip;
print $o{$ip};# or:
my $subnet = '10.0.0';
$subnet = join '', map{ sprintf "%02x",$_} split /\./, $subnet;
my @range = (12 .. 49);foreach (@range){
print $o{join '', $subnet, sprintf "%02x",$_}, "\n";
};_______________________________________________ Perl-Win32-Admin mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
