use strict; use diagnostics; use warnings; use LWP::UserAgent; use LWP::Simple; use HTML::LinkExtor; use URI::URL; my $url = "http://www.remote.dk/~user/beta/"; my $ua = LWP::UserAgent->new; my @links = (); sub callback { my($tag, %attr) = @_; return if $tag eq 'href'; push(@links, values %attr); return (@links); } my $p = HTML::LinkExtor->new(\&callback); my $res = $ua->request(HTTP::Request->new(GET => $url), sub {$p->parse($_[0])}); my $base = $res->base; @links = map {$_ = url($_, $base)->abs;} @links; my @betas = grep(/tar/, @links); foreach my $beta (@betas) { my @remote_files = head($beta); my $length = $remote_files[1]; my $bprecise = sprintf "%.0f", $length; my $bsize = insert_commas($bprecise); my $kprecise = sprintf "%.0f", ($length/1024); my $ksize = insert_commas($kprecise); my $archtype; # tarball? or bzip2? or zip? my $betahref = substr($beta, 40, 70); if ($beta =~ /tar.gz/) { $archtype = "(tarball)"; } elsif ($beta =~ /bz2/) { $archtype = "(bzip)"; } else { $archtype = "(zip)"; } print a({-href=>"$beta"}, "$betahref"), " $archtype
${ksize}kb, $bsize bytes", br,br; } ################################################# # # Insert commas in numeric lengths, so the number # 1234567 would be 1,234,567 # ################################################# sub insert_commas { local($_) = @_; 1 while s/(\d+)(\d\d\d)/$1,$2/; $_; }