Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: Strip user-defined words with regexp

by Marcello (Hermit)
on Mar 04, 2004 at 19:12 UTC ( #333977=note: print w/replies, xml ) Need Help??


in reply to Re: Strip user-defined words with regexp
in thread Strip user-defined words with regexp

Out of curiosity: why not just
my ($word1, $word2) = split(/[^A-Za-z0-9]+/, $message);
?

Marcel

Replies are listed 'Best First'.
Re: Re: Re: Strip user-defined words with regexp
by BrowserUk (Pope) on Mar 04, 2004 at 19:56 UTC

    Given the OP's examplei input

    With the grep

    $message = "\n +_ ABC1_\n2 3 4"; print join'|', ( grep $_, split /[^A-Za-z0-9]+/ , $message )[0,1]; ABC1|2

    Without

    $message = "\n +_ ABC1_\n2 3 4"; print join'|', split /[^A-Za-z0-9]+/ , $message; |ABC1|2|3|4

    You'll notice the null leading element.

    The list slice is pretty redundant, but it does make it obvious that you are only wanting the first two.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2020-05-30 16:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (173 votes). Check out past polls.

    Notices?