Now more efficient and no longer redundant.
Additionally, it should be noted that Net::Ping::new() defaults to TCP, therefore any "dead" repository merely failed to reply to a TCP ping. Some "dead" domains will reply to alternative protocol pings (eg SourceForge does not reply to TCP, but does reply to ICMP).
use strict;
use warnings;
use PPM::Repositories;
use Net::Ping;
foreach my $repository (split(/[\r\n]/, `ppm rep`)) {
next unless $repository =~ s/^\[[\d\ ]+\]\ (.*)$/$1/;
system("ppm rep delete $repository > NUL") unless $repository =~ /
+activestate/i;
}
foreach my $repository (keys %Repositories) {
my $domain = my $location = $Repositories{$repository}->{location}
+;
next unless $domain =~ s|^\s*http://([^/]+)/.*$|$1|;
if (Net::Ping->new()->ping($domain)) {
print "$repository is alive.\n";
system("ppm repository add $repository $location > NUL");
} else {
print "$repository is dead.\n";
}
}
print $/, `ppm rep`;
Output:
dada is dead.
smueller is alive.
crazy58 is alive.
crazy is alive.
datetime is alive.
soulcage58 is alive.
bribes is alive.
gtk is dead.
rto is alive.
spurkis is dead.
theoryS is dead.
jenda is dead.
theory58S is dead.
log4perl is dead.
theory58 is dead.
soulcage is alive.
savage is dead.
devhelp is alive.
theory is dead.
openi is dead.
roth is alive.
Repositories:
[ 1] ActiveState Package Repository
[ 2] ActiveState PPM2 Repository
[ 3] smueller
[ 4] crazy58
[ 5] crazy
[ 6] datetime
[ 7] soulcage58
[ 8] bribes
[ 9] rto
[10] soulcage
[11] devhelp
[12] roth
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|