#!/usr/bin/perl # cli2hatena use strict; my %hash; my $date; while(<>){ my ($url, $tit) =split(/\t/,$_); ($date) = ($url =~ /(\d{4}-\d\d-\d\d)/); next unless ($url =~ s!^.+"(.+)".+$!http://nais.to/~yto/clog/$1!); $tit =~ s!\[.+?\]\s*$!!g; unshift @{$hash{$date}}, {url=>$url,title=>$tit}; } my $all = qq(<?xml version="1.0" encoding="UTF-8"?>\n<diary>\n); foreach (sort {$b cmp $a} keys %hash) { $all .= qq(<day date="$_" title="">\n<body>\n); my $ctr; foreach (@{$hash{$_}}) { $ctr++; $all .= qq(*p$ctr*$_->{title}\n$_->{url}\n); } $all .= qq(</body>\n</day>\n); } $all .= qq(</diary>); use Jcode; print Jcode->new($all)->utf8;
cli2hatena.pl cl.itemlist > hd.xml