J
Jerome Abela
Hi there,
The following code comes directly from perlre(1), except it's inside a
sub:
animals();
animals();
sub animals {
my ($color, $animal);
$_ = "The brown fox jumps over the lazy dog";
/the (\S+)(?{ $color = $^N }) (\S+)(?{ $animal = $^N })/i;
print "color = $color, animal = $animal\n";
}
But its output is surprizing (at least with v5.8.5 and v5.8.7):
color = brown, animal = fox
color = , animal =
Everything works if I don't declare lexical variables, so it may be
related to some kind of scoping from inside the (?{}). But I can't find
any reasonable explanation for this behavior.
I need help from more knowledgeable people: how can I write more robust
code to be used from (?{}) expressions ?
Or, as an alternative, how can I store data matched inside nested
groups ? My real original code is more like:
m/special\((?:before(group)after(?{save it, using $^N}))*\)/
where the {save using $^N} part only works once because of the bug
above.
Jerome.
The following code comes directly from perlre(1), except it's inside a
sub:
animals();
animals();
sub animals {
my ($color, $animal);
$_ = "The brown fox jumps over the lazy dog";
/the (\S+)(?{ $color = $^N }) (\S+)(?{ $animal = $^N })/i;
print "color = $color, animal = $animal\n";
}
But its output is surprizing (at least with v5.8.5 and v5.8.7):
color = brown, animal = fox
color = , animal =
Everything works if I don't declare lexical variables, so it may be
related to some kind of scoping from inside the (?{}). But I can't find
any reasonable explanation for this behavior.
I need help from more knowledgeable people: how can I write more robust
code to be used from (?{}) expressions ?
Or, as an alternative, how can I store data matched inside nested
groups ? My real original code is more like:
m/special\((?:before(group)after(?{save it, using $^N}))*\)/
where the {save using $^N} part only works once because of the bug
above.
Jerome.