Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Mixed Unicode and ANSI string comparisons?

by BrowserUk (Patriarch)
on Dec 14, 2015 at 22:48 UTC ( [id://1150299]=note: print w/replies, xml ) Need Help??


in reply to Re: Mixed Unicode and ANSI string comparisons?
in thread Mixed Unicode and ANSI string comparisons?

What have you tried?

Nothing! I know just enough about Unicrap to know that I want nothing to do with it.

But something came up. Hence; I'm asking for expert help.

#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; use open OUT => ':utf8', ':std'; use Encode; my @strings = ("\N{LATIN SMALL LETTER C WITH CARON}", "c", "\N{LATIN SMALL LETTER C WITH CEDILLA}", "\N{LATIN SMALL LETTER C WITH ACUTE}"); push @strings, map encode('utf-8', $_), @strings; say for sort @strings;

Hm. That code tells me nothing useful and neither does the output:

C:\test>\perl22\bin\perl.exe junk33.pl c c ç ć č ç ć č

Except maybe that sort readily accept mixed scalars, which doesn't make any sense at all to me.

How can it compare and collate strings that exist in two entirely different encoding spaces?

And interleaving them is like interleaving Chinese and Cyrillic strings; make no sense at all.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^3: Mixed Unicode and ANSI string comparisons?
by Anonymous Monk on Dec 14, 2015 at 22:57 UTC
    How can it compare and collate strings that exist in two entirely different encoding spaces?
    Yeah... just like that :)

    To be fair, Unicode::Collate is what does real collating, and it's very good.

Re^3: Mixed Unicode and ANSI string comparisons?
by exilepanda (Friar) on Dec 17, 2015 at 08:28 UTC
    #! /usr/bin/perl is useless in windows ( and wrong path here )

    Your code don't need that complex. Follow code works as well

    use warnings; use strict; use utf8; use feature "say"; binmode STDOUT, ":utf8"; my $unicodeStr = "..."; # assign your own Unicode char as I can't type + Unicode in here say for sort ($uniCodeStr, "user login" ) ;
    One problem is that, when you run the script inside a CMD console, it's default code page is ANSI, but whatever codepage you set (chcp) , you will not able to print a proper result ( from my experience ).

    To print a proper result, you might want to use tools like PowerShell or NppExec(a plugin) with Notepad++ ( you also have to set the output encoding for this plugin )

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-28 20:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found