juliosergio has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to use what was matched by a regular expression utilized in the 'split' function, so I wrote something like:
@a2 = split /(abc)/, "uno abc dos"; ... some use of $1 ...
However this doesn't work, because, I guess, 'split' doesn't treat /(abc)/ as a regular expression. See the following example:
#! /usr/bin/perl @a1 = split /abc/, "uno abc dos"; @a2 = split /(abc)/, "uno abc dos"; print "@a1\n"; # prints "uno dos", as expeted print "@a2\n"; # prints "uno abc dos" !!! :(
Can you explain me why is it so?, and what can I do to recover the string matched by the regular expression?
Thanks,
-Sergio
|
|---|