NAME

Decode::ARGV - Decode the command-line arguments to characters

SYNOPSIS

use Decode::ARGV; # decodes from UTF-8

use Decode::ARGV 'cp1252';

$ perl -MDecode::ARGV -E'say "Argument contains only word characters" unless $ARGV[0] =~ m/\W/' 'слово'

DESCRIPTION

This module provides simple in-place decoding of command-line arguments in the global array @ARGV. As with most input and output, command-line arguments are provided to the script in bytes, and must be decoded to characters before performing string operations like length or regex matches.

The -CA switch for Perl performs a similar function, but this has some deficiencies. It assumes via the :utf8 internal layer that the arguments are valid UTF-8 bytes, ignoring invalid Unicode, and even resulting in malformed strings if the bytes do not happen to be well-formed UTF-8. This switch is also difficult to use in a script and cannot decode the arguments from other encodings.

PARAMETERS

use Decode::ARGV;
use Decode::ARGV 'lax';
use Decode::ARGV 'Shift_JIS';
use Decode::ARGV lax => 'Shift_JIS';

$ perl -MDecode::ARGV ...
$ perl -MDecode::ARGV=lax ...
$ perl -MDecode::ARGV=Shift_JIS ...
$ perl -MDecode::ARGV=lax,Shift_JIS ...

By default, Decode::ARGV will decode @ARGV in-place using "decode_utf8" in Encode::Simple, which will throw an exception if any argument doesn't contain valid well-formed UTF-8 bytes.

lax can be specified as the first (optional) import parameter to instead use "decode_utf8_lax" in Encode::Simple, leaving replacement characters in the resulting strings instead of throwing an exception.

The next optional import parameter specifies an alternate encoding to expect from the command-line, in which case "decode" in Encode::Simple or "decode_lax" in Encode::Simple will be used to decode the arguments from that encoding.

BUGS

Report any issues on the public bugtracker.

AUTHOR

Dan Book <dbook@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2021 by Dan Book.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

SEE ALSO

Encode::Simple