B
Bill
Hello, I've got a regex question.
In the following, the use of () in an 'or' type regex causes @a to
hold both captures, so for each pass through the regex, one capture
and one undef is stored.
Can this be prevented and still use () captures and '|' in the regex?
my $s = '1 2 {3, 3, 3} 4';
my @a = $s =~ m/\{[^\}]+\}|\d/g;
print "\nWithout captures:\n", join "\n", @a;
@a = $s =~ m/(\{[^\}]+\})|(\d)/g;
foreach(@a) { $_ = 'undef' unless $_; }
print "\n\nNow with captures:\n", join "\n", @a;
<<<<<<<<<<<
In the following, the use of () in an 'or' type regex causes @a to
hold both captures, so for each pass through the regex, one capture
and one undef is stored.
Can this be prevented and still use () captures and '|' in the regex?
my $s = '1 2 {3, 3, 3} 4';
my @a = $s =~ m/\{[^\}]+\}|\d/g;
print "\nWithout captures:\n", join "\n", @a;
@a = $s =~ m/(\{[^\}]+\})|(\d)/g;
foreach(@a) { $_ = 'undef' unless $_; }
print "\n\nNow with captures:\n", join "\n", @a;
<<<<<<<<<<<