Headerを表示する

use strict;
use warnings;
use LWP::UserAgent;
use YAML;

print Dump get_header($ARGV[0]);


sub get_header
{
    my ($url) = @_;
    my %hash;
    my $res = LWP::UserAgent->new(timeout => 10)->head($url);
    if ($res->is_success) {
        foreach my $line (split /\n/, $res->as_string) {
            my ($key, $val) = split /\:\s*/, $line;
            next unless $val;
            $hash{$key}=$val;
        }
    }
    return \%hash;
}