Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: unicode DWIM?

by dakkar (Hermit)
on Feb 24, 2005 at 13:29 UTC ( #434058=note: print w/ replies, xml ) Need Help??


in reply to unicode DWIM?

I'm not sure get_layers is the best way to get the name of the locale's encoding, but assuming it is, this works: (Perl 5.8.2 linux)

use open ':locale'; use Encode; use strict; my $locEnc; for (PerlIO::get_layers(STDOUT)){ if (/encoding\((.*)\)/ || /(utf8)/ ){ $locEnc=$1;last; } } print "Locale encoding: $locEnc\n"; for (@ARGV) { $_=Encode::decode($locEnc,$_) } my $i=1; for (@ARGV) { print $i++," '",$_,"'(",length($_),")\n"; }

It decodes (in place) each command-line argument from the locale's encoding, then prints them alongside their length. This helps in understanding what kind of strings Perl thinks it is working with.

-- 
        dakkar - Mobilis in mobile

Most of my code is tested...

Perl is strongly typed, it just has very few types (Dan)


Comment on Re: unicode DWIM?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2015-07-05 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls