Re: Sorting IP addresses - Progress
Re: Sorting IP addresses - Progress
- Subject: Re: Sorting IP addresses - Progress
- From: Doug McNutt <email@hidden>
- Date: Sun, 21 Dec 2003 12:15:35 -0700
These are too fast for stopwatch timing with less than 10^5 entries.
OS 10.2.8 caches the files so disk activity is not important on my G4 sawtooth at 375 MHz.
Perhaps someone will create the "do shell script" interface and make it on-topic.
It's probably possible to implement the two-way base 256 conversions in AppleScript. I have not used any features, like bit shifts and 64 bit integers, which are not available in AppleScript.
##################
File: IPrandomize.pl
#!/usr/bin/perl
# Sample CLI command to create a test file
# perl -w IPrandomize.pl 100000 > IPrandom100000
$howmany = $ARGV[0]; # Argument is count to be prepared.
$twohat32 = 2**32;
$ipsep = ".";
@numlist = ();
for ($lynn = 0; $lynn < $howmany; $lynn++)
{
push @numlist, int(rand() * $twohat32);
}
while(@numlist)
{
$num = (shift @numlist) / $twohat32;
$line = "";
for ($lynn = 0; $lynn < 4; $lynn++)
{
$num = $num * 256;
$m = int($num);
$num = $num - $m;
$line = $line.$m.$ipsep;
}
chop $line;
print "$line\r";
}
##################
File: IPsort.pl
#!/usr/bin/perl
# Sample CLI command to sort the created test file
# perl -w IPsort.pl IPrandom100000 > IPsorted100000
$tempFile = $ARGV[0];
open SOURCE, $tempFile or die "No source file $tempFile";
$twohat32 = 2**32;
$ipsep = ".";
@numlist = ();
$/ = "\r"; # Line ends on source are Mac returns.
while (<SOURCE>)
{
@spl = split /\./, $_;
$num = 0;
while (@spl)
{
$num = $num*256 + shift @spl;
}
push @numlist, $num;
}
close SOURCE;
@sorted = sort {$b <=> $a;} @numlist;
while(@sorted)
{
$num = (shift @sorted) / $twohat32;
$line = "";
for ($lynn = 0; $lynn < 4; $lynn++)
{
$num = $num * 256;
$m = int($num);
$num = $num - $m;
$line = $line.$m.$ipsep;
}
chop $line;
print "$line\r";
}
##################
--
--> There are 10 kinds of people: those who understand binary, and those who don't <--
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.