kikuchiyo has asked for the wisdom of the Perl Monks concerning the following question:
And it failed with this error message:use utf8; my $€ = 1; print $€;
This version, however, ran correctly:Malformed UTF-8 character (unexpected end of string) at utf8test.pl li +ne 3. Unrecognized character \x82 in column 5 at utf8test.pl line 3.
So it seems that while certain unicode characters can be in variable names, others cause an error.use utf8; my $á = 1; print $á;
The results (omitted here) show that indeed, certain characters don't seem to be eligible as variable names.#!/usr/bin/perl use strict; use warnings; use utf8; use charnames ':full'; my ($fh, $rfh); my ($vname, $errorcode, $message, $col, $byte); open($rfh, '>>:encoding(UTF-8)', 'utf8report.txt') || die 'Error openi +ng file'; for (0x100..0x9fff) { # You may want to change these numbers if the sc +ript runs for too long open($fh, '>:encoding(UTF-8)', 'utf8test.pl') || die 'Error openin +g file'; print $fh "use utf8;\n"; $vname = pack "U", $_; print $fh "my \$$vname = $_;\nprint \$$vname;"; close $fh; #system "perl", "-c", "utf8test.pl"; $message = `perl -c utf8test.pl 2>&1`; ($byte, $col) = $message =~ /character \\x(..).*column (\d)/; $errorcode = ($? >> 8) ? "FAIL at byte ".($col-4)."($byte)" : "PAS +S"; print $rfh "$_\t$errorcode, character ".(charnames::viacode($_))." +\n"; print $_-$_%100,"\r"; } print "\n"; close $rfh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: UTF-8 characters in variable names: some characters are not allowed
by ikegami (Patriarch) on Sep 06, 2009 at 18:05 UTC | |
by moritz (Cardinal) on Sep 06, 2009 at 18:24 UTC | |
by ikegami (Patriarch) on Sep 06, 2009 at 18:32 UTC |