perl-unicode

Re: Second call to Unicode::UCD::charscript() returns different results.

2003-07-18 02:30:06
terry(_at_)eatoni(_dot_)com (terry jones) writes:

I know no-one in their right mind would want to do this, but...

The code below produces an unexpected (for me) result. The first call
to read_script() reports 23 codepoint ranges. The second reports 0.

Regards,
Terry.

----------------------------------------------------------------------
#!/usr/bin/perl -w

use Unicode::UCD 'charscript';

sub read_script {
    my $script = shift;
    my $ranges = charscript($script);

    printf "Read script $script. %d ranges exist.\n", scalar(@$ranges);
    
    while (my $range = shift @$ranges){
      printf "%06X -> %06X\n", $$range[0], $$range[1];
    }
}

read_script('Latin');
read_script('Latin');


I think, I'd do something like this patch. All tests pass and your
test is fixed. Current bleadperl does return 26 though.

--- perl-p-5(_dot_)8(_dot_)0(_at_)20166/lib/Unicode/UCD.pm      2003-07-18 
08:49:42.000000000 +0200
+++ perl-p-5(_dot_)8(_dot_)0(_at_)20166-ak/lib/Unicode/UCD.pm   2003-07-18 
10:37:57.000000000 +0200
@@ -5,6 +5,8 @@
 
 our $VERSION = '0.2';
 
+use Storable qw(dclone);
+
 require Exporter;
 
 our @ISA = qw(Exporter);
@@ -31,7 +33,7 @@
     my $charblock  = charblock($codepoint);
 
     use Unicode::UCD 'charscript';
-    my $charscript = charblock($codepoint);
+    my $charscript = charscript($codepoint);
 
     use Unicode::UCD 'charblocks';
     my $charblocks = charblocks();
@@ -320,7 +322,7 @@
        _search(\(_at_)BLOCKS, 0, $#BLOCKS, $code);
     } else {
        if (exists $BLOCKS{$arg}) {
-           return $BLOCKS{$arg};
+           return dclone $BLOCKS{$arg};
        } else {
            return;
        }
@@ -385,7 +387,7 @@
        _search(\(_at_)SCRIPTS, 0, $#SCRIPTS, $code);
     } else {
        if (exists $SCRIPTS{$arg}) {
-           return $SCRIPTS{$arg};
+           return dclone $SCRIPTS{$arg};
        } else {
            return;
        }
@@ -407,7 +409,7 @@
 
 sub charblocks {
     _charblocks() unless %BLOCKS;
-    return \%BLOCKS;
+    return dclone \%BLOCKS;
 }
 
 =head2 charscripts
@@ -425,7 +427,7 @@
 
 sub charscripts {
     _charscripts() unless %SCRIPTS;
-    return \%SCRIPTS;
+    return dclone \%SCRIPTS;
 }
 
 =head2 Blocks versus Scripts
@@ -709,7 +711,7 @@
 
     _casespec() unless %CASESPEC;
 
-    return $CASESPEC{$code};
+    return ref $CASESPEC{$code} ? dclone $CASESPEC{$code} : $CASESPEC{$code};
 }
 
 =head2 Unicode::UCD::UnicodeVersion




-- 
andreas

<Prev in Thread] Current Thread [Next in Thread>