Perl 5.8 and Perl 5.10 Porting - Unicode Error

A

Aqua

I have a simple script

=====
use charnames ':full';

$ReNum = qr/(\\d+[A-Z]?)/i;
$ReNumRng = qr/$ReNum[\N{EN DASH}]$ReNum/;
$Line = "foo";
$Line =~ /$ReNumRng/;
=====

This works in perl 5.8 and I am getting a big error in 5.10.

Constant(\N{EN DASH}) unknown: (possibly a missing "use
charnames ...") in regex
; marked by <-- HERE in m/(?i-xsm:(\\d+[A-Z]?))[\N{EN DASH} <-- HERE ]
(?i-xsm:(\
\d+[A-Z]?))/ at C:\projects\test.pl line 4.

Appreciate any help in resolving this.

Regards
Dominic
 
A

Aqua

This works for me in 5.10.1:
use charnames ':full';

print "[\N{EN DASH}]\n";
my $dash = "\N{EN DASH}";
my $enre = qr"[${dash}]";
print "$enre\n";

A few quick stabs using eval didn't work.

Dear Eli,

My web server admins suddenly upgraded perl version to 5.10.x and I
was also suggested to use

$ReNumRng = encode("UTF-8","qr/$ReNum[\N{EN DASH}]$ReNum/");

I am not sure here as I have so many references to different unicode
"long" names. I am using qr to pre-compile my regex and check for
matches on the strings.

Appreciate further suggestions.

Regards
Dominic
 
S

sln

I have a simple script

=====
use charnames ':full';

$ReNum = qr/(\\d+[A-Z]?)/i;
$ReNumRng = qr/$ReNum[\N{EN DASH}]$ReNum/;
$Line = "foo";
$Line =~ /$ReNumRng/;
=====

This works in perl 5.8 and I am getting a big error in 5.10.

Constant(\N{EN DASH}) unknown: (possibly a missing "use
charnames ...") in regex
; marked by <-- HERE in m/(?i-xsm:(\\d+[A-Z]?))[\N{EN DASH} <-- HERE ]
(?i-xsm:(\
\d+[A-Z]?))/ at C:\projects\test.pl line 4.

I verify this quirk on 5.10.

I always thought quoting in qr// is different than qq//.
I never quite trust qr// for constants when mixed with variables.

-sln


use strict;
use warnings;

use charnames ':full';

print "\n1:\t", qr/ a [\N{EN DASH}] b /, "\n";
print "\n2:\t", qq/ c [\N{EN DASH}] d /, "\n";

my $Dash = qq/[\N{EN DASH}]/;
my $ReNum = qr/(\d+[A-Z]?)/;
my $ReNumRng = qr/$ReNum$Dash$ReNum/;
print "\n3:\t$ReNumRng\n\n";

my $var = 'a';
print "----------------------\n";
print "\n", qr/ ${var} [\N{EN DASH}] b /, "\n";

__END__



1: (?-xism: a [\N{EN DASH}] b )

2: c [–] d

3: (?-xism:(?-xism:(\d+[A-Z]?))[–](?-xism:(\d+[A-Z]?)))
 
S

sln

I have a simple script

=====
use charnames ':full';

$ReNum = qr/(\\d+[A-Z]?)/i;
$ReNumRng = qr/$ReNum[\N{EN DASH}]$ReNum/;
$Line = "foo";
$Line =~ /$ReNumRng/;
=====

This works in perl 5.8 and I am getting a big error in 5.10.

Constant(\N{EN DASH}) unknown: (possibly a missing "use
charnames ...") in regex
; marked by <-- HERE in m/(?i-xsm:(\\d+[A-Z]?))[\N{EN DASH} <-- HERE ]
(?i-xsm:(\
\d+[A-Z]?))/ at C:\projects\test.pl line 4.

I verify this quirk on 5.10.

I always thought quoting in qr// is different than qq//.
I never quite trust qr// for constants when mixed with variables.

-sln


use strict;
use warnings;

use charnames ':full';

print "\n1:\t", qr/ a [\N{EN DASH}] b /, "\n";
print "\n2:\t", qq/ c [\N{EN DASH}] d /, "\n";

my $Dash = qq/[\N{EN DASH}]/;
my $ReNum = qr/(\d+[A-Z]?)/;
my $ReNumRng = qr/$ReNum$Dash$ReNum/;
print "\n3:\t$ReNumRng\n\n";

my $var = 'a';
print "----------------------\n";
print "\n", qr/ ${var} [\N{EN DASH}] b /, "\n";

__END__



1: (?-xism: a [\N{EN DASH}] b )

2: c [–] d

3: (?-xism:(?-xism:(\d+[A-Z]?))[–](?-xism:(\d+[A-Z]?)))

Add use re 'debug'; for some interresting insight as to what the use charnames module
seems to do. Its like a user defined function for Unicode properties, like \p{your function}
does.

-sln
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top