Tatsuhiko Miyagawa's Blog

Run a tweet like Perl

August 19, 2009

Takesako-san and other shibuya.pm folks brought up the wonderful idea on the IRC channel that any URL can be used as a valid JavaScript code, since in JS “:” is a label and “//” is the beginning of comment.

Of course, we then started to figure out how to do that with Perl :)

`% perl -MO=Deparse -e http://goog.com/search

http: //go . ‘com’ / ‘search’;

`

The http: is considered as a label similarly, and //goog now becomes an empty match against $_. So well, as long as you use the first hostname that only consists of ‘cgimosx’ (Let’s call it perl-safe hostname), any URL can be parsed as a valid perl.

The next thing is easy: get an arbitrary Twitter permalink URL and run the tweet text as a perl. Unfortunately “twitter” is not a perl-safe hostname, so you need to change the hostname to ‘m.twitter.com’ :) but otherwise it’s all straightforward: overload com and status to get the ID by avoiding division-by-zero runtime error, and in the END block, fetch a tweet and run it as a perl script.

There you go:

`% perl -Mtwitter -e http://m.twitter.com/miyagawa/status/3412563203

ok`

Enjoy, of course at your own risk – if someone tweets like system(“rm -rf $ENV{HOME}”) and your hard drive is wiped, don’t blame me :)