Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Seeking a better way to do it

by vinoth.ree (Monsignor)
on Feb 01, 2013 at 05:15 UTC ( #1016438=note: print w/replies, xml ) Need Help??


in reply to Seeking a better way to do it

Use grep!!!

my $char_list = "Enter Iago, Othello, and others"; my @Word_List = grep { /[A-Z]\w+/ } split(/\W/, $char_list); print "@Word_List\n";
Update:

Simple way with regular expression,

my $char_list = "Enter Iago, Othello, and others"; my @Word_List; @Word_List = ($char_list =~ /([A-Z]\w+)/g); print "@Word_List\n";

Replies are listed 'Best First'.
Re^2: Seeking a better way to do it
by Tux (Abbot) on Feb 01, 2013 at 07:33 UTC

    That would also match camelCase and Some_shell, you'd want

    my @wordlist = ($string =~ m{\b ([A-Z][a-z]+) \b}gx);

    as BrowserUK also posted


    Enjoy, Have FUN! H.Merijn
Re^2: Seeking a better way to do it
by frozenwithjoy (Priest) on Feb 01, 2013 at 05:22 UTC
    This works assuming OP also wants to return 'Enter'. This is left out of the requirements, but I'm not sure if it is an oversight or not.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016438]
help
Chatterbox?
[Corion]: marto: Oooh - cinema... I guess that's something I could do with my godson and sibling and sister as well, but I guess that getting a six year old and two four year olds into one movie is a tough sell ;)
[marto]: busy weekend, no me time :P
[Corion]: marto: Yeah, that's somewhat implied :) I was on the phone with my godson yesterday (they birthday), but I haven't seen them for two weeks now (vacation), relaxing, but I somewhat miss them too ;)
[Discipulus]: me waterpolo? oh no! i'm a no sport; the tournment was for the elder son
[karlgoethebier]: good morning
[Corion]: Discipulus: Ah, so he's the one getting almost drowned all the time - waterpolo certainly is no sport for me ;)
[karlgoethebier]: Corion: buy enough coke and popcorn...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2017-07-24 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (348 votes). Check out past polls.