Skip to content

Instantly share code, notes, and snippets.

@f99aq8ove
Created January 22, 2011 15:32
Show Gist options
  • Save f99aq8ove/791181 to your computer and use it in GitHub Desktop.
Save f99aq8ove/791181 to your computer and use it in GitHub Desktop.
parse JSON only
--- a/Stream.pm 2011-01-23 00:27:05.243140965 +0900
+++ b/Stream.pm 2011-01-23 00:28:17.402025511 +0900
@@ -154,7 +154,7 @@
my($handle, $json) = @_;
# Twitter stream returns "\x0a\x0d\x0a" if there's no matched tweets in ~30s.
$set_timeout->();
- if ($json) {
+ if ($json && $json =~ /^{/) {
my $tweet = $decode_json ? JSON::decode_json($json) : $json;
if ($on_delete && $tweet->{delete} && $tweet->{delete}->{status}) {
$on_delete->($tweet->{delete}->{status}->{id}, $tweet->{delete}->{status}->{user_id});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment