in reply to How can I place each "word" of a string in a varible if I don't know the length of the string?
@words = $string =~ m/(\w+)/g;This will place each matching item into the array @words, the matching criteria is a greedy comparison on \w that gives a word character ie. not a space,tab,comma...etc.
The g at the the end of the regular expression is "global" so it will keep doing the match regardless of the string length. Regular Expressions are a very good place to start whenever you want to do tricksy stuff with a string.
Good sources of learning are:
I hope this helps ;^)
--Brother Frankus.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regular expressions to store matching patterns in an array.
by ketema (Scribe) on Jun 22, 2005 at 20:58 UTC | |
by planetscape (Chancellor) on Jun 23, 2005 at 18:21 UTC |