Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

In reply to Stream of Consciousness by beretboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (6)
    As of 2020-04-03 11:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The most amusing oxymoron is:
















      Results (27 votes). Check out past polls.

      Notices?