[tpm] problems with what regex returns ... in context ?
Kwan Tamakanic
quantum.mechanic.1964 at gmail.com
Fri May 10 16:12:25 PDT 2013
Source:
#!/usr/bin/env perl
use strict;
use warnings;
my $regex = 'one';
my $prompt = "? ";
print $prompt;
while (<>) {
if (my @capture = /$regex/ig) {
foreach (@capture) {
print "($.) found <$_>\n";
}
} else {
print "($.) didn't match\n";
}
print $prompt;
}
exit;
Result:
%> capture.pl
? One oNe onE two
(1) found <One>
(1) found <oNe>
(1) found <onE>
? three
(2) didn't match
? four
(3) didn't match
? ^C
I would say, if for you, @capture is always true, then it's getting some
value outside the scope you have shown us.
-QM
On Fri, May 10, 2013 at 10:01 PM, Rob Janes <janes.rob at gmail.com> wrote:
> if (my @cap = /$regex/) {
> @cap = ($&) unless defined $1;
> foreach @cap {
> do something;
> }
> }
> On May 10, 2013 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
>>
>>
--
-QM
Quantum Mechanics: The dreams stuff is made of
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130511/268c18fb/attachment-0001.html>
More information about the toronto-pm
mailing list