Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

How to specify Encode:: <subchar>?

by Marcello (Hermit)
on Mar 18, 2008 at 09:21 UTC ( [id://674750]=perlquestion: print w/replies, xml ) Need Help??

Marcello has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

From the Encode documentation:
Handling Malformed Data ... CHECK = Encode::FB_DEFAULT ( == 0) If CHECK is 0, (en|de)code will put a substitution character in place +of a malformed character. When you encode, <subchar> will be used.
I have been looking all over, but how can I specify this <subchar>? The default is '?' but I would like to use a space instead.

Thanks!

Replies are listed 'Best First'.
Re: How to specify Encode:: <subchar>?
by ikegami (Patriarch) on Mar 18, 2008 at 12:49 UTC
    How about
    use constant FB_SPACE => sub { ' ' }; $bytes = encode($charset, $chars, FB_SPACE);

    Update: Tested:

    use Encode qw( encode FB_DEFAULT ); use HTML::Entities qw( decode_entities ); use constant FB_SPACE => sub { ' ' }; my $chars = decode_entities('abc&hearts;def'); my $charset = 'US-ASCII'; for my $check (FB_DEFAULT, FB_SPACE) { print encode($charset, $chars, $check), "\n"; }
    abc?def abc def
      Thanks ++ikegami,

      Upgraded my Encode version from 2.01 to the latest 2.24 and using this new functionality.

      Regards, Marcel
Re: How to specify Encode:: <subchar>?
by hipowls (Curate) on Mar 18, 2008 at 10:32 UTC

    <subchar> is specified in a Unicode Character Map (UCM) file. They are used by enc2xs (part of Encode) to generate xs files to be compiled into an encoding. The documentation for enc2xs has a quick guide for making your own encoding.

    If all you want to do is change the substitution character then it should be simple. Find the UCM file for the encoding you want to modify, change <subchar> to the value you want and follow the instructions.

    Good luck!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://674750]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-04-24 09:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found