2 # $Id: piconv,v 1.20 2002/04/04 19:50:52 dankogai Exp dankogai $
8 my %Scheme = map {$_ => 1} qw(from_to decode_encode perlio);
12 my %Opt; getopts("hDS:lf:t:s:", \%Opt);
14 $Opt{l} and list_encodings();
15 my $locale = $ENV{LC_CTYPE} || $ENV{LC_ALL} || $ENV{LANG};
16 $Opt{f} || $Opt{t} || help();
17 my $from = $Opt{f} || $locale or help("from_encoding unspecified");
18 my $to = $Opt{t} || $locale or help("to_encoding unspecified");
19 $Opt{s} and Encode::from_to($Opt{s}, $from, $to) and print $Opt{s} and exit;
20 my $scheme = exists $Scheme{$Opt{S}} ? $Opt{S} : 'from_to';
23 my $cfrom = Encode->getEncoding($from)->name;
24 my $cto = Encode->getEncoding($to)->name;
33 if ($scheme eq 'from_to'){
35 Encode::from_to($_, $from, $to); print;
38 }elsif ($scheme eq 'decode_encode'){
40 my $decoded = decode($from, $_);
41 my $encoded = encode($to, $decoded);
45 }elsif ($scheme eq 'perlio'){
46 binmode(STDIN, ":encoding($from)");
47 binmode(STDOUT, ":encoding($to)");
50 die "unknown scheme: $scheme";
54 print STDERR join("\n", Encode->encodings(":all")), "\n";
61 my $name = basename($0);
62 $message and print STDERR "$name error: $message\n";
64 $name [-f from_encoding] [-t to_encoding] [-s string] [files...]
66 -l lists all available encodings.
67 -f from_encoding When omitted, the current locale will be used.
68 -t to_encoding When omitted, the current locale will be used.
69 -s string "string" will be converted instead of STDIN.
78 piconv -- iconv(1), reinvented in perl
82 piconv [-f from_encoding] [-t to_encoding] [-s string] [files...]
87 B<piconv> is perl version of F<iconv>, a character encoding converter
88 widely available for various Unixen today. This script was primarily
89 a technology demonstrator for Perl 5.8.0, you can use piconv in the
90 place of iconv for virtually any cases.
92 piconv converts character encoding of either STDIN or files specified
93 in the argument and prints out to STDOUT.
95 Here are list of options.
99 =item -f from_encoding
101 Specifies the encoding you are converting from. Unlike F<iconv>,
102 this option can be omitted. In such cases the current locale is used.
106 Specifies the encoding you are converting to. Unlike F<iconv>,
107 this option can be omitted. In such cases the current locale is used.
109 Therefore when both -f and -t are omitted, F<piconv> just acts like F<cat>.
113 uses I<string> instead of file for the source of text. Same as F<iconv>.
117 Lists all available encodings to STDERR.
125 Invokes debugging mode. Primarily for Encode hackers.
129 Selects which scheme is to be used for conversion. Available schemes
136 Uses Encode::from_to for conversion. This is the default.
140 Input strings are decode()d then encode()d. A straight two-step
145 The new perlIO layer is used. NI-S' favorite.
149 Like I<-D> option, this is also for Encode hackers.