If you read up on 'User-Defined Character Properties' in
perlunicode.pod,
it says:
Note that the effect is compile-time and immutable once
defined.
This suggest that if you define a property IsFoo, the
subroutine IsFoo
is called once and perl caches the result.
This turns out not to be the case, as the following program
shows:
#!/usr/bin/perl
use strict;
use warnings;
no warnings 'syntax';
use Test::More tests => 1;
use feature ':5.10';
# Returns alternating 0x41 ('A') and 0x42 ('B').
sub IsFoo {
state $flag = 1;
$flag ++ % 2 ? "0041n" :
"0042n";
}
ok "AB" =~ /pp/;
__END__
1..1
ok 1
For each occurrence in the regexp, IsFoo() is called.
This is quite unfortunate. Is the documentation wrong? Do I
misinterpret
the documentation? Should the result be cached and is there
a bug?
If it's not a bug, consider the caching behaviour to be a
feature request.
Abigail
|