in reply to Strip user-defined words with regexp

This might meet the reqs?

my( $word1, $word2 ) = ( grep $_, split /[^A-Za-z0-9]+/, $message )[0, +1]

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

Replies are listed 'Best First'.
Re: Re: Strip user-defined words with regexp
by Marcello (Hermit) on Mar 04, 2004 at 19:12 UTC
    Out of curiosity: why not just
    my ($word1, $word2) = split(/[^A-Za-z0-9]+/, $message);
    ?

    Marcel

      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