Just to give an example of how /x can help here, look at the code below. Let us assume that $_ contains data in the form id|name|address|city|state|postal. So:
/\A ( # $1 -- Entire string (hey, why not?) ([^|]+) \| # $2 -- id ([^|]+) \| # $3 -- address ([^|]+) \| # $4 -- city ([^|]+) \| # $5 -- state ([^|]+) # $6 -- postal )\z/x;
IMHO, it's more impressive to make smart use of \x than being able to make use of bizzare regex features.
----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer
: () { :|:& };:
Note: All code is untested, unless otherwise stated
In reply to Re^5: Capturing everything after an optional character in a regex?
by hardburn
in thread Capturing everything after an optional character in a regex?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |