[tpm] problems with what regex returns ... in context ?
Tom Legrady
legrady at gmail.com
Fri May 10 16:00:41 PDT 2013
When a regex has a capture, the return value of m// is the list of matched
substrings. When it does not capture, it returns a boolean to indicate
whether it matched or not. That's why you can do:
if ( $line =~ /$pattern/o ) { .... }
Newer perls allow naming of captures within the RE. Read the Captures
section of perldoc perlre:
Additionally, as of Perl 5.10.0 you may use named capture buffers and
named backreferences. The notation is "(?<name>...)" to declare and
"\k<name>" to reference. You may also use apostrophes instead of
angle
brackets to delimit the name; and you may use the bracketed
"\g{name}"
backreference syntax. It’s possible to refer to a named capture
buffer
by absolute and relative number as well. Outside the pattern, a
named
capture buffer is available via the "%+" hash.
Tom
On Fri, May 10, 2013 at 4:47 PM, Quantum Mechanic <
quantum.mechanic.1964 at gmail.com> wrote:
>
> On Fri, May 10, 2013 at 1:33 PM, Quantum Mechanic <
> quantum.mechanic.1964 at gmail.com> wrote:
>
>> I would have tried "my" instead of the punctuation variables:
>>
>> if (my @capture = /$regex/) {
>> foreach @capture {
>> do something;
>> }
>> }
>>
>
> That doesn't make any difference, @capture still (seems to get) the 1/true
> result code
> when there is no capturing.
>
>
>
> It should create a new @capture each time. It doesn't always capture
> something, right? I'll have to try it when I get home.
>
>
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130510/edb855e6/attachment.html>
More information about the toronto-pm
mailing list