Thursday, August 25, 2011

my little perl script to uncomment the mirrorlist

so am a perl newbie and i want to start writing little utilities that make it easy for me to do stuff. i have just written a little script that lets me uncomment the Servers in mirrorlist contained in /etc/pacman.d/mirrorlist and its working pretty good. its not the best but hey, it works for me:

#!/usr/bin/perl
#
use strict;
use warnings;

open MIRRORS, "/home/me/mirrorlist";
my $i = 0;
while () {
if (/(Server.*)/) {
print "$1\n";
}
}
close MIRRORS;
i then ./mirrors.pl > mymirrorlist
and rankmirrors -n 6 mymirrorlist > mirrorlist
tada!

[EDIT]
this can even run better like this, i just learnt to do subs, so
#!/usr/bin/perl
#
use strict;
use warnings;

open MIRRORS, "/home/tehpwnz/perl/mirrorlist";
open MYLIST, ">/home/tehpwnz/perl/list";
my $i = 0;
while () {
#if(/[#]Server.*(http|ftp)/) {
# print "found";
#}
if (/(Server.*)/) {
s/#//;
print MYLIST;
}
}
close MIRRORS;
close MYLIST;

1 comment:

  1. never mind the $i=0 part, that was for debugging something i just forgot to remove it :(

    ReplyDelete