http://qs321.pair.com?node_id=269708

Word association has long been used as a phsycoanalytic tool, as has it's visual counterpart, the Rorschach Inkblot test. I have adapted this idea from serious tool to amusing distraction. Sorry about the embedded HTML, this was just a quick hack. Every now and then, it will have a broken image, and I can think of a few ways to fix it but for now, c'est la vie. Here is how it works. You will be presented with a word and a picture, and asked to enter the first word that comes to mind. Remember to enter only one word, otherwise the script will ignore you. The word you enter will then be used to fetch a new image (via Google) which the next person will then respond to. You can do this as many times as you want with one exception, you cannot respond to your own word/picture. The neat part is the subroutine "image", which scrapes http://images.google.com
The Demo is Here: Stream of Consciousness
#!/usr/bin/perl use strict; use CGI qw( param header ); sub image { # Give it a word, it gives you an image! use LWP::UserAgent; my $word = shift; my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/2525010 +1'); my $request = HTTP::Request->new('GET','http://images.google.com/i +mages?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&q=' . $word); my $response = $ua->request($request); my $data = $response->content; my @urls = ($data =~ m/\?imgurl=(.*?)&/g); my $url = $urls[rand @urls]; $url = 'http://' . $url; } print header; my $word = param("word"); $word =~ s/<(.*?)>//g; $word =~ s/\+//g; !($word =~ / /) || die "ONE WORD ONLY"; if ($word) { print <<HEAD; <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" +> <title>The Stream</title> <head> <body text="#ffffff" bgcolor="#000000" link="#ffffff" alink="#ffffff" +vlink="#ffffff"> <center><font size=+8>The Stream</font><center> <hr size=1 width=35%> HEAD my $ip = $ENV{"REMOTE_ADDR"}; open(RLASTIP,"lastip") || die "File Open Failed: $!"; my $lastip = <RLASTIP>; close(RLASTIP); if (!($ip eq $lastip)) { my $url = image($word); open(WLIST,">>list"); print WLIST "$word $url\n"; close WLIST; open(WLASTIP,">lastip") || die "File Open Failed: $!"; print WLASTIP "$ip"; close(WLASTIP); } else { print "<script>alert(\"Your association was not added because you +did the last one. You cannot respond to your own.\\n Try again later +when someone has responded to your thought.\");</script>"; } open(RLIST,"list"); my @list = <RLIST>; close(RLIST); foreach $_(@list) { my ($link,$linkurl); ($link,$linkurl) = split(" ", $_); print "<center><A HREF=\"$linkurl\">$link</A></center>"; } print "<hr size=1 width=35%>\n</body>\n</html>"; } else { open(RLIST,"list") || die "File Open Failed: $!";; my $lastline; $lastline = $_ while <RLIST>; close(RLIST); my ($lastword,$lasturl); ($lastword,$lasturl) = split(" ", $lastline); print <<MONKEY; <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" +> <title>Stream of Consciousness</title> <head> <body text="#ffffff" bgcolor="#000000" link="#ffffff" alink="#ffffff" +vlink="#ffffff6"> <center><font size=+8>Stream of Consciousness</font><center> <hr size=1 width=55%> <br> <center><img src="$lasturl"><center> <center><font size=+5>$lastword</font></center> <center> <hr size=1 width=55%> <br> <b>Enter The First Word That Comes To Mind</b> <form method="post" action="stream.cgi"> <center><input type="text" name="word" style="background:#000000; colo +r:#ffffff"></center> <br> <center><input type="Submit" name="submit" value="submit" class="butto +n" style="background:#000000; color:#ffffff"></center> </form> </center> </body> </html> MONKEY }


"Sanity is the playground of the unimaginative" -Unknown