Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

[A follow-up to "Re: Decoding @ARGV [Was: uparse - Parse Unicode strings]".]

I'm not going to have sufficient spare time to do all that I wanted this weekend. I have managed to incorporate your changes and do a couple of other minor things.

When prefixing the uparse command with PERL_UNICODE=A or PERL_UNICODE=SDAL, I just get "Wide character at ..." and no other output. I made these changes:

  • Added changes from your patch.
  • Changed "use open IO ..." to "use open OUT ...".
  • Modified the code layout (mostly to avoid wrapping in PM).

Here's the new code:

#!/usr/bin/env perl BEGIN { if ($] < 5.007003) { warn "$0 requires Perl v5.7.3 or later.\n"; exit; } unless (@ARGV) { warn "Usage: $0 string [string ...]\n"; exit; } } use 5.007003; use strict; use warnings; use open OUT => qw{:encoding(UTF-8) :std}; use constant { SEP1 => '=' x 60 . "\n", SEP2 => '-' x 60 . "\n", FMT => "%s\tU+%-6X %s\n", NO_PRINT => "\N{REPLACEMENT CHARACTER}", }; use Encode qw{decode is_utf8}; use Unicode::UCD 'charinfo'; for my $raw_str (@ARGV) { my $str = is_utf8($raw_str) ? $raw_str : decode('UTF-8', $raw_str); print "\n", SEP1; print "String: '$str'\n"; print SEP1; for my $char (split //, $str) { my $code_point = ord $char; my $char_info = charinfo($code_point); if (! defined $char_info) { $char_info->{name} = "<unknown> Perl $^V supports Unicode " . Unicode::UCD::UnicodeVersion(); } printf FMT, ($char =~ /^\p{Print}$/ ? $char : NO_PRINT), $code_point, $char_info->{name}; } print SEP2; }

Here's a test run with just uparse:

$ uparse 👮🏼 👮🏼‍♀️ 👮🏼‍♂️

============================================================
String: '👮🏼'
============================================================
👮      U+1F46E  POLICE OFFICER
🏼      U+1F3FC  EMOJI MODIFIER FITZPATRICK TYPE-3
------------------------------------------------------------

============================================================
String: '👮🏼‍♀️'
============================================================
👮      U+1F46E  POLICE OFFICER
🏼      U+1F3FC  EMOJI MODIFIER FITZPATRICK TYPE-3
        U+200D   ZERO WIDTH JOINER
♀       U+2640   FEMALE SIGN
        U+FE0F   VARIATION SELECTOR-16
------------------------------------------------------------

============================================================
String: '👮🏼‍♂️'
============================================================
👮      U+1F46E  POLICE OFFICER
🏼      U+1F3FC  EMOJI MODIFIER FITZPATRICK TYPE-3
        U+200D   ZERO WIDTH JOINER
♂       U+2642   MALE SIGN
        U+FE0F   VARIATION SELECTOR-16
------------------------------------------------------------

And again, this time with PERL_UNICODE=A:

$ PERL_UNICODE=A uparse 👮🏼 👮🏼‍♀️ 👮🏼‍♂️

============================================================
String: '👮🏼'
============================================================
👮      U+1F46E  POLICE OFFICER
🏼      U+1F3FC  EMOJI MODIFIER FITZPATRICK TYPE-3
------------------------------------------------------------

============================================================
String: '👮🏼‍♀️'
============================================================
👮      U+1F46E  POLICE OFFICER
🏼      U+1F3FC  EMOJI MODIFIER FITZPATRICK TYPE-3
        U+200D   ZERO WIDTH JOINER
♀       U+2640   FEMALE SIGN
        U+FE0F   VARIATION SELECTOR-16
------------------------------------------------------------

============================================================
String: '👮🏼‍♂️'
============================================================
👮      U+1F46E  POLICE OFFICER
🏼      U+1F3FC  EMOJI MODIFIER FITZPATRICK TYPE-3
        U+200D   ZERO WIDTH JOINER
♂       U+2642   MALE SIGN
        U+FE0F   VARIATION SELECTOR-16
------------------------------------------------------------

Using "PERL_UNICODE=SDAL" gives the same output as "PERL_UNICODE=A".

— Ken


In reply to Re: Decoding @ARGV [Was: uparse - Parse Unicode strings] by kcott
in thread uparse - Parse Unicode strings by kcott

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-16 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found