Perl 5.8 and Perl 5.10 Porting - Unicode Error

Discussion in 'Perl Misc' started by Aqua, Apr 9, 2011.

  1. Aqua

    Aqua Guest

    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
    Aqua, Apr 9, 2011
    #1
    1. Advertising

  2. Aqua

    Aqua Guest

    > 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
    Aqua, Apr 10, 2011
    #2
    1. Advertising

  3. Aqua

    Guest

    On Sat, 9 Apr 2011 00:19:31 -0700 (PDT), Aqua <> wrote:

    >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]?)))

    ----------------------
    Constant(\N{EN DASH}) unknown: (possibly a missing "use charnames ...") in regex
    ; marked by <-- HERE in m/ a [\N{EN DASH} <-- HERE ] b / at pp.pl line 16.
    , Apr 10, 2011
    #3
  4. Aqua

    Guest

    On Sun, 10 Apr 2011 11:10:26 -0700, wrote:

    >On Sat, 9 Apr 2011 00:19:31 -0700 (PDT), Aqua <> wrote:
    >
    >>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]?)))
    >
    >----------------------
    >Constant(\N{EN DASH}) unknown: (possibly a missing "use charnames ...") in regex
    >; marked by <-- HERE in m/ a [\N{EN DASH} <-- HERE ] b / at pp.pl line 16.
    >


    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
    , Apr 11, 2011
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kj
    Replies:
    10
    Views:
    455
  2. Grzegorz ¦liwiñski
    Replies:
    2
    Views:
    957
    Grzegorz ¦liwiñski
    Jan 19, 2011
  3. Mark Wilson
    Replies:
    2
    Views:
    152
    Robert Feldt
    Sep 25, 2003
  4. Replies:
    1
    Views:
    103
    Logan Capaldo
    Aug 8, 2006
  5. Mentifex
    Replies:
    2
    Views:
    329
    Mentifex
    Dec 28, 2012
Loading...

Share This Page