9 use Encode::Guess qw/shift-jis euc-jp 7bit-jis/;
10 use File::Temp qw/ :POSIX /;
12 my $target = shift @ARGV || die "$0: URL or file-of-url-list [coding]\n";
13 my $coding = shift @ARGV || 'utf8';
15 my $ua = LWP::UserAgent->new;
18 if ($target !~ /^http/ && -f $target) {
19 open(my $fh, "<$target");
26 foreach my $url (@URLs) {
28 my $tmpfile = tmpnam();
29 my $res = $ua->mirror($url, $tmpfile);
31 if ($res->is_success) {
32 my $filename = $res->filename;
33 my $decoder = Encode::Guess->guess($filename);
38 $decoder->decode($filename),
46 decode("utf8", $filename),
50 print ": $filename\n";
53 my $savename = $filename;
54 while (-e $savename) {
55 $savename = "$filename.$suffix";
58 rename($tmpfile, $savename);