#! perl -w use strict; my $discard = ; $discard = ; my %data; my @prefix; my $in_tag; while (defined (my $line=)) { if ($line =~ m!^\s*<([^<>/]+)>\s*$!) { push @prefix, $1; } elsif ($line =~ m!^\s*/]+)>\s*$!) { pop @prefix; if (not @prefix and keys %data) { handle_entry(%data); } } elsif ($line =~ m!^\s*<([^<>/]+)>(.*)/]+>\s*$!) { my $key = join('-', @prefix, $1); my $val = $2; # there should always be a leading 'user' object $key =~ s!^user-!!; $data{$key} = $val; #print "$key -> $val\n"; } elsif ($line =~ m!^\s*<[^<>/]+/>\s*$!) { # empty tag, ignore } elsif ($line =~ m!^\s*!) { # multi-line recent tweet, skip the whole thing $in_tag='text'; } elsif (defined $in_tag) { # skip it, but check for the end if ($line =~ m!\s*$!) { undef $in_tag; } } else { warn "unrecognised line $line"; } } sub handle_entry { my %data = @_; print "$data{id}\t$data{screen_name}\t$data{name}\n"; }