xmlからデータ引っこ抜いた後、Rで遊べるようにデータの加工をやった。そのためのスクリプト。
#!/usr/bin/perl use strict; use warnings; use XML::LibXML; use LWP::Simple; my $path = "/home/yasuhisa/svn/public/perl/friends"; opendir( DIR, $path ); my @files = grep { s/(.*)\.xml/$1/ } readdir(DIR); closedir(DIR); foreach my $friend (@files) { &writeFollowers($friend); } sub getFollowers() { my $username = shift; my $path = "/home/yasuhisa/svn/public/perl/friends"; my $file = "$path/$username.xml"; my $parser = XML::LibXML->new; my $dom = $parser->parse_file($file) or die; my @names = $dom->getElementsByTagName("screen_name"); my @friends = (); foreach (@names) { push( @friends, $_->firstChild->data ); } return @friends; } sub writeFollowers() { my $name = shift; my $path = "/home/yasuhisa/svn/public/perl/friends"; my $text = ""; my @list = &getFollowers($name); foreach my $friend (@list) { $text = $text . "$friend\n"; } my $file = "$path/$name.txt"; open( FILE, "> $file" ) or die $!; print FILE $text; close(FILE); }