Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

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

A few approaches, some already covered by others:

  • The split approach produces a lot of 'noise' (even when using a more reasonable  /\W+/ split pattern) that must be removed with further processing.
  • A tricky approach is to try to figure out just what a 'player' is and define a regex to extract those substrings.
  • Maybe the easiest and most reliable approach is to go to the dramatis personae list at the beginning of the play, look at all the players found there, and make a regex of that.

>perl -wMstrict -le "my $char_list = 'Exit Cassio; Enter Iago, Othello, and others'; ;; my @words = split /\W+/, $char_list; printf qq{'$_' } for @words; print ''; ;; ;; my $not_player = qr{ (?! Enter | Exit) }xms; my $player = qr{ \b $not_player [[:upper:]] [[:lower:]]+ }xms; ;; my @players = $char_list =~ m{ $player }xmsg; printf qq{'$_' } for @players; print ''; ;; ;; my @dramatis_personae = qw(Cassio Iago Othello); my ($character) = map qr{ \b (?: $_) \b }xms, join '|', @dramatis_personae ; ;; @players = $char_list =~ m{ $character }xmsg; printf qq{'$_' } for @players; " 'Exit' 'Cassio' 'Enter' 'Iago' 'Othello' 'and' 'others' 'Cassio' 'Iago' 'Othello' 'Cassio' 'Iago' 'Othello'

In reply to Re: Seeking a better way to do it by AnomalousMonk
in thread Seeking a better way to do it by starX

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!
  • 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 chilling in the Monastery: (7)
    As of 2015-07-04 06:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (58 votes), past polls