Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Following talk in the CB today, I started poking through the latest XML ticker, which shows the list of all monks at the monastery. I was struck by how many of the usernames were similar to real words. Combining that with my wish to play with Text::Soundex gave me..

The wonderful toy of Monastery::Monkify. It changes every word into a link to the home node of a monk with a similar name. Unfortunatly, Text::Soundex isn't picky enough to get really good matches, but it's still fun. Anyways, the code:

use strict; use Text::Soundex; use LWP::Simple; use HTML::Entities; $Text::Soundex::nocode = 'Z000'; $| = 1; print "Loading.."; my @nodes = map {($_)=/"([^"]+)"/;defined($_)?[$_,soundex($_)=~/(.)(.{ +3})/]:['','Z',0]} split /\n/, get 'http://perlmonks.org/?node_id=74291'; print "Done.\n"; s/(\w+)/bestfit($1)/ge, print while <>; sub bestfit { my($word) = @_; my @se = soundex($word)=~ /(.)(.{3})/; return "[nodereaper|$word]" if join('',@se) eq 'Z000'; my @found = sort {abs($se[1]-$a->[2]) <=> $se[1]-$b->[2]} grep {$se[ +0] eq $_->[1]} @nodes; return "[".decode_entities $found[rand(grep {$found[0][2] == $_->[2] +} @found)]->[0]."|$word]"; }

Note: I'm doing a somewhat evil thing here, by processing XML using regexes. I'm forced to do this, however, because the "XML" node in question isn't actually XML -- it has non-XML entities. Ah, well..

 
perl -e 'print "I love $^X$\"$]!$/"#$&V"+@( NO CARRIER'


In reply to Monastery::Monkify by Chmrr

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 making s'mores by the fire in the courtyard of the Monastery: (6)
    As of 2020-04-08 17:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The most amusing oxymoron is:
















      Results (45 votes). Check out past polls.

      Notices?