Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

beatnik poetry generator

by Boldra (Deacon)
on Apr 04, 2001 at 18:22 UTC ( #69673=CUFP: print w/ replies, xml ) Need Help??

perl -e 'while(<>){chomp;$words{join"",reverse split//}=$_} foreach(so +rt keys %words){print"$words{$_}\n"}'</usr/share/dict/words
Then try reading the list alloud while playing your bongo drums :)

(the location of your words file may vary - the above is for redhat)

Comment on beatnik poetry generator
Download Code
Replies are listed 'Best First'.
Re: beatnik poetry generator
by ChemBoy (Priest) on Apr 06, 2001 at 22:01 UTC
    Well, if short is the goal, then I suggest  perl -lne '$words{reverse $_}=$_; END{foreach(sort keys %words){print $words{$_}}}' /usr/share/dict/words

    Ain't command-line switches grand? Or of course (if you ignore the convenience of reversing a string): perl -F// -lane '$words{join"",reverse @F}=$_; END{foreach(sort keys %words){print $words{$_}}}' /usr/share/dict/words
    Though you might consider that overdoing it (or, alternatively, half-assed obfuscation). I just really like autosplit. :-)

    To make it a mesmerizing background instead of a printed list, stick a sleep 0.1 statement in the foreach loop. Then remember to look away after a while to refocus your eyes. <grin>

    But however you run it, it's cool.

    Ooh! Ooh! Now I feel just despicably clever. Recalling the Schwartzian Transform and other list-oriented fun, I now present what I'd guess is the shortest possible generator: perl -e 'print sort {reverse ($a) cmp reverse ($b)} <>' /usr/share/dict/words Man, I love list context...

    If God had meant us to fly, he would *never* have give us the railroads.
         --Michael Flanders
      Yes! I Love that last version! Well done!

      One minor cleanup might be:
      perl -e 'print sort {reverse lc($a) cmp reverse lc($b)} <>' /usr/share +/dict/words

      But then, you probably want to skip acronyms altogether, so I'm not sure if that's a good idea.

      And my favourite viewing method is something like this:
      /usr/X11R6/lib/xscreensaver/phosphor -root -delay 50000 -program "beat < /usr/share/dict/words"
      You gotta love the jwz screensavers (perl-hater though he is :).

        The case issue occured to me later, but I don't think it makes much difference--acronyms, as you say, are about it, and there aren't that many of them in the dictionary. I'd figure out how many, but the local Linux boxes are all having screaming fits today, so I can't right now (unless somebody wants to tell me where to find the words file on IRIX, which I'm not convinced is there at all).

        Thanks for the tip on the screen-saver--might have to try that.

        If God had meant us to fly, he would *never* have give us the railroads.
             --Michael Flanders

Re: beatnik poetry generator
by buckaduck (Chaplain) on Apr 06, 2001 at 00:57 UTC
    Isn't this code:
    $words{join"",reverse split//}=$_
    just a convoluted version of this?
    $words{reverse $_}=$_
    Or is there some subtle difference? Or maybe you meant it to be obfuscated, I dunno...


      No it wasn't meant to be obfuscated, just short. So your suggestion is definitely an improvement, many thanks!
        Please Pay Attention Students

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://69673]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2015-11-28 07:03 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (739 votes), past polls