Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: matching characters eg

by davido (Cardinal)
on May 27, 2020 at 14:46 UTC ( #11117340=note: print w/replies, xml ) Need Help??


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: Hppy 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:

  1. Accept input
  2. Transform input to a native format.
  3. Work with the native format string.
  4. Transform from native to external format.
  5. 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11117340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2021-01-22 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?