#!/usr/bin/perl -w # I wrote this silly script to find the most efficient way to examine # the Path header looking for a bad site. # The break even point is at about 6 or 7 bad sites to check in the path. # It's one or two elements higher when checking a very short path. # # Conclusions: # splitting the path and checking it with the for loop is worth it. use strict; my $path = 'wonderland.linux.it!bofh.it!kirk.uli.it!newsfeed.cineca.it!newsserver.cilea.it!newsmi-eu.news.garr.it!newsrm.news.garr.it!NewsITBone-GARR!news.unina.it!studenti.unina.it!falemagna'; my @check = qw( optus news1.rivrw1.nsw.optushome.com.au.POSTED gts news.unitel.co.kr ns.sampanet.gr.jp netnews.hinet.net news.vcd.cl ); #kaktus.farlep.net news.ukr.net news.reimliga.de ); my $check1 = join('|', @check); $check1 =~ s/\./\\./; my %check2 = map { $_ => 1 } @check; #timethese(1000000, {'uno' => &match1, 'due' => &match2, }); exit 0; for (my $i = 0; $i < 1000; $i++) { print "ERR\n" if match1(); } for (my $i = 0; $i < 1000; $i++) { print "ERR\n" if match2(); } exit 0; sub match1 { return 1 if $path =~ /$check1/o; return 0; } sub match2 { my @p = split(/!/, $path); foreach (@p) { return 1 if exists $check2{$_}; } return 0; }