List Info

Thread: User-Defined Character Properties immutable?




User-Defined Character Properties immutable?
user name
2007-09-07 15:33:23
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
Re: User-Defined Character Properties immutable?
user name
2007-09-15 23:35:57
On 9/7/07, Abigail <abigailabigail.be> wrote:
> 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.

While attempting to redefine the character class IdFirst I
ran across
oodles of code which stashed this stuff into private data. I
don't
really recall whether it was perl-side or c-side. Mostly I
think it
was c-side stuff. Piles of "swash"-fu were getting
written to and
didn't appear to be written to twice.

Just on that generalized recollection I'm surprised to hear
your
function is called multiple times but I'd gather it's the
expectation.

Josh

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )