2 # $Id: piconv,v 1.24 2002/04/22 02:45:50 dankogai Exp $
8 my %Scheme = map {$_ => 1} qw(from_to decode_encode perlio);
12 my %Opt; getopts("pcC: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';
22 $Opt{p} and $Opt{C} = Encode::FB_PERLQQ;
25 my $cfrom = Encode->getEncoding($from)->name;
26 my $cto = Encode->getEncoding($to)->name;
35 if ($scheme eq 'from_to'){
37 Encode::from_to($_, $from, $to, $Opt{C}); print;
40 }elsif ($scheme eq 'decode_encode'){
42 my $decoded = decode($from, $_, $Opt{C});
43 my $encoded = encode($to, $decoded);
47 }elsif ($scheme eq 'perlio'){
48 binmode(STDIN, ":encoding($from)");
49 binmode(STDOUT, ":encoding($to)");
52 die "unknown scheme: $scheme";
56 print join("\n", Encode->encodings(":all")), "\n";
63 my $name = basename($0);
64 $message and print STDERR "$name error: $message\n";
66 $name [-f from_encoding] [-t to_encoding] [-s string] [files...]
68 -l lists all available encodings (the canonical names, many aliases exist)
69 -f from_encoding When omitted, the current locale will be used.
70 -t to_encoding When omitted, the current locale will be used.
71 -s string "string" will be converted instead of STDIN.
80 piconv -- iconv(1), reinvented in perl
84 piconv [-f from_encoding] [-t to_encoding] [-s string] [files...]
89 B<piconv> is perl version of B<iconv>, a character encoding converter
90 widely available for various Unixen today. This script was primarily
91 a technology demonstrator for Perl 5.8.0, but you can use piconv in the
92 place of iconv for virtually any case.
94 piconv converts the character encoding of either STDIN or files
95 specified in the argument and prints out to STDOUT.
97 Here is the list of options.
101 =item -f from_encoding
103 Specifies the encoding you are converting from. Unlike B<iconv>,
104 this option can be omitted. In such cases, the current locale is used.
108 Specifies the encoding you are converting to. Unlike B<iconv>,
109 this option can be omitted. In such cases, the current locale is used.
111 Therefore, when both -f and -t are omitted, B<piconv> just acts
116 uses I<string> instead of file for the source of text. Same as B<iconv>.
120 Lists all available encodings, one per line, in case-insensitive
121 order. Note that only the canonical names are listed; many aliases
122 exist. For example, the names are case-insensitive, and many standard
123 and common aliases work, such as "latin1" for "ISO-8859-1", or "ibm850"
124 instead of "cp850", or "winlatin1" for "cp1252". See L<Encode::Supported>
125 for a full discussion.
129 Check the validity of the stream if I<N> = 1. When I<N> = -1, something
130 interesting happens when it encounters an invalid character.
146 Invokes debugging mode. Primarily for Encode hackers.
150 Selects which scheme is to be used for conversion. Available schemes
157 Uses Encode::from_to for conversion. This is the default.
161 Input strings are decode()d then encode()d. A straight two-step
166 The new perlIO layer is used. NI-S' favorite.
170 Like the I<-D> option, this is also for Encode hackers.