Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: sorting domains by extention

by Abigail-II (Bishop)
on Aug 27, 2002 at 11:13 UTC ( #193128=note: print w/ replies, xml ) Need Help??

in reply to sorting domains by extention

You don't need a full sort, all you want is to put the domains in the proper buckets. Here's my solution:

#!/usr/bin/perl use strict; use warnings 'all'; my @regexes = map {qr /\.$_$/} qr {co\.uk}, qr {com}, # No need for the [\w\-] prefix. qr {pl}, # qr {uk\.com}, # This one already gets grabbed by \.com ; my @domains = qw { }; my @buckets = map {[]} @regexes, 1; DOMAIN: foreach my $domain (@domains) { for (my $i = 0; $i < @regexes; $i ++) { next unless $domain =~ qr /$regexes[$i]/; push @{$buckets [$i]} => $domain; next DOMAIN; } push @{$buckets [-1]} => $domain; } print "$_\n" for map {@$_} @buckets; __END__

Comment on Re: sorting domains by extention
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://193128]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2015-12-01 08:04 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (796 votes), past polls