in reply to parse a string

Something like
my $String = " something, something, something, this "; my ( $LastWord ) = $String =~ m/(\w+)\s$/;
would probably work. The '$' anchors the pattern to the end of the string, and the brackets around the LastWord variable are to keep things in a list context.

--t. alex

"Nyahhh (munch, munch) What's up, Doc?" --Bugs Bunny

Replies are listed 'Best First'.
Re: Re: parse a string
by Molt (Chaplain) on May 03, 2002 at 15:05 UTC

    This works provided the last section consists of only alphanumerics, since \w won't match anything else. Try this on the string 'Some people don't' and it only matches the 't', using the \S solution is probably safer in the long term.

    Nice use of the inline substitution though, really should get more used to using that idiom.