in reply to matching characters eg å
Convert from non-native representations at the boundaries; as close to ingress and egress as possible. Here's an example:
#!/usr/bin/env perl BEGIN { binmode STDOUT, ':encoding(utf-8)'; } use strict; use warnings; use utf8; use HTML::Entities; my $input = "Håppy"; print "Input was: $input\n"; my $native = decode_entities($input); print "Decoded to native format: $native\n"; if ($native =~ m/å/) { print "Found an å.\n"; }
The output is:
Input was: Håppy Decoded to native format: Håppy Found an å.
By converting from an HTML entity at the point closest to ingress you don't have to worry anymore about dealing with a layer that adds complexity to manipulating the string.
Think in terms like this:
- Accept input
- Transform input to a native format.
- Work with the native format string.
- Transform from native to external format.
- Send output to external resource.
If you always keep transformations as close to the edge as possible your code will be a lot simpler.
Dave
|
---|
In Section
Seekers of Perl Wisdom