Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use strict;
- use utf8;
- my $test_string = '£100 $cash i am a ☃ you are a ☹';
- print "First Regex\n";
- while ($test_string =~ m/([\$£]+)/g) {
- my $res = $1;
- if (utf8::is_utf8($res)) {
- print "Unicode encoding to utf8\n";
- utf8::encode($res);
- }
- print "match: $res\n";
- }
- print "Second Regex\n";
- while ($test_string =~ m/(\p{Symbol})/g) {
- my $res = $1;
- if (utf8::is_utf8($res)) {
- print "Unicode encoding to utf8\n";
- utf8::encode($res);
- }
- print "match: $res\n";
- }
- if (utf8::is_utf8($test_string)) {
- print "NOW TRY ENCODED UTF8 DATA\n";
- utf8::encode($test_string);
- print "ENCODED: $test_string\n";
- }
- print "Third Regex Notice that we loose the snowman and frowny face \n";
- while ($test_string =~ m/([\$£]+)/g) {
- my $res = $1;
- if (utf8::is_utf8($res)) {
- print "Unicode encoding to utf8\n";
- utf8::encode($res);
- }
- print "match: $res\n";
- }
- print "Fourth Regex\n";
- while ($test_string =~ m/(\p{Symbol})/g) {
- my $res = $1;
- if (utf8::is_utf8($res)) {
- print "Unicode encoding to utf8\n";
- utf8::encode($res);
- }
- print "match: $res\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment