SHOW:
|
|
- or go back to the newest paste.
| 1 | #!/usr/bin/perl -w | |
| 2 | ||
| 3 | use strict; | |
| 4 | use utf8; | |
| 5 | ||
| 6 | my $test_string = '£100 $cash i am a ☃ you are a ☹'; | |
| 7 | print "First Regex\n"; | |
| 8 | while ($test_string =~ m/([\$£]+)/g) {
| |
| 9 | my $res = $1; | |
| 10 | if (utf8::is_utf8($res)) {
| |
| 11 | print "Unicode encoding to utf8\n"; | |
| 12 | utf8::encode($res); | |
| 13 | } | |
| 14 | print "match: $res\n"; | |
| 15 | } | |
| 16 | ||
| 17 | ||
| 18 | ||
| 19 | print "Second Regex\n"; | |
| 20 | while ($test_string =~ m/(\p{Symbol})/g) {
| |
| 21 | my $res = $1; | |
| 22 | if (utf8::is_utf8($res)) {
| |
| 23 | print "Unicode encoding to utf8\n"; | |
| 24 | utf8::encode($res); | |
| 25 | } | |
| 26 | print "match: $res\n"; | |
| 27 | } | |
| 28 | ||
| 29 | - | # now encode test_string as UTF8 |
| 29 | + | |
| 30 | print "NOW TRY ENCODED UTF8 DATA\n"; | |
| 31 | utf8::encode($test_string); | |
| 32 | print "ENCODED: $test_string\n"; | |
| 33 | } | |
| 34 | ||
| 35 | ||
| 36 | ||
| 37 | print "Third Regex Notice that we loose the snowman and frowny face \n"; | |
| 38 | while ($test_string =~ m/([\$£]+)/g) {
| |
| 39 | my $res = $1; | |
| 40 | if (utf8::is_utf8($res)) {
| |
| 41 | print "Unicode encoding to utf8\n"; | |
| 42 | utf8::encode($res); | |
| 43 | } | |
| 44 | print "match: $res\n"; | |
| 45 | } | |
| 46 | print "Fourth Regex\n"; | |
| 47 | while ($test_string =~ m/(\p{Symbol})/g) {
| |
| 48 | my $res = $1; | |
| 49 | if (utf8::is_utf8($res)) {
| |
| 50 | print "Unicode encoding to utf8\n"; | |
| 51 | utf8::encode($res); | |
| 52 | } | |
| 53 | print "match: $res\n"; | |
| 54 | } |