>>>>> "Andy" == Andy Wardley <[EMAIL PROTECTED]> writes:
Andy> I'd also like a 'matches' method that returns a reference to a list
Andy> of the matches. That would allow you to do things like this:
Andy> [% string.matches('(.).*').0 %] # first character
Andy> or:
Andy> [% matches = string.matches('(\w+)\s+(\w+)') %]
Andy> first word: [% matches.0 %]
Andy> second word: [% matches.1 %]
Andy> and so on.
I couldn't easily think of a way to adapt this to substitutions, but
you can do this:
my @matches = $string =~ /(\w+)\s+(\w+)/;
and then $matches[0] is the $1, etc. In fact, you could
just return that array from a "matches", and let me capture it
and play with it. Then if I want to do a fancy replacement, I could
do this:
[% m = string.matches('(.*?)(\w+)\s+(\w+)(.*)');
m.0; m.2; " "; m.1; m.3 %]
which swaps the first two \w+ words. How about that? Can we have that?
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!