6.9. Encode/Decode

简介:

6.9.1. Text::Iconv

use Text::Iconv;
$converter = Text::Iconv->new("fromcode", "tocode");
$converted = $converter->convert("Text to convert");
			

6.9.2. Encode::Guess -- Guesses encoding from data

http://perldoc.perl.org/Encode/Guess.html

			
  # if you are sure $data won't contain anything bogus

  use Encode;
  use Encode::Guess qw/euc-jp shiftjis 7bit-jis/;
  my $utf8 = decode("Guess", $data);
  my $data = encode("Guess", $utf8);   # this doesn't work!

  # more elaborate way
  use Encode::Guess;
  my $enc = guess_encoding($data, qw/euc-jp shiftjis 7bit-jis/);
  ref($enc) or die "Can't guess: $enc"; # trap error this way
  $utf8 = $enc->decode($data);
  # or
  $utf8 = decode($enc->name, $data)
			
			

6.9.3. URI::Escape

 use URI::Escape;
 $safe = uri_escape("10% is enough\n");
 $verysafe = uri_escape("foo", "\0-\377");
 $str  = uri_unescape($safe);





原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
|
6月前
|
编解码 数据可视化 Java
Java如何进行Base64的编码(Encode)与解码(Decode)?
Java如何进行Base64的编码(Encode)与解码(Decode)?
313 1
|
编解码 Python
pandas - read_csv报错:‘utf-8‘/‘gbk‘ codec can‘t decode byte 0xb1 in position 0:invalid start byte
pandas - read_csv报错:‘utf-8‘/‘gbk‘ codec can‘t decode byte 0xb1 in position 0:invalid start byte
418 0
|
存储 JSON 安全
base64_encode()和base64_decode(),URL的加密解密详解
base64_encode()和base64_decode(),URL的加密解密详解
441 0
|
Python
Python3 ‘str‘ object has no attribute ‘decode‘. Did you mean: ‘encode‘?
Python3 ‘str‘ object has no attribute ‘decode‘. Did you mean: ‘encode‘?
287 0
|
Cloud Native 关系型数据库 OLAP
可以使用内置的函数`encode()`
可以使用内置的函数`encode()`
129 0
|
编解码 Python
【pandas问题】UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xca in position 0: invalid continuati
【pandas问题】UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xca in position 0: invalid continuati
499 0
|
存储 自然语言处理 JavaScript
python 的encode和decode
python 的encode和decode
python 的encode和decode
|
编解码 Python
UnicodeEncodeError: 'ascii' codec can't encode characters
UnicodeEncodeError: 'ascii' codec can't encode characters
175 0
成功解决TypeError: Won't implicitly convert Unicode to bytes; use .encode()
成功解决TypeError: Won't implicitly convert Unicode to bytes; use .encode()
|
Python
Python编码介绍——encode和decode
在 python 源代码文件中,如果你有用到非ASCII字符,则需要在文件头部进行字符编码的声明,声明如下: # code: UTF-8 因为python 只检查 #、coding 和编码字符串,所以你可能回见到下面的声明方式,这是有些人为了美观等原因才这样写的: #-*- cod...
946 0