Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Seeking a better way to do it

by AnomalousMonk (Abbot)
on Feb 01, 2013 at 06:25 UTC ( #1016457=note: print w/ replies, xml ) Need Help??


in reply to Seeking a better way to do it

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'


Comment on Re: Seeking a better way to do it
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016457]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (15)
As of 2015-07-06 12: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 (74 votes), past polls