当前位置:网站首页>Encoding type of Perl conversion file
Encoding type of Perl conversion file
2022-06-30 20:25:00 【Mountain sound and water moon】
List of articles
Sometimes there is a need to convert the encoding type of files , Although most of the current text editing software provides the function of conversion , But batch conversion is still inconvenient . Wrote a small function , Can carry on utf8->gbk or gbk->utf8 Transformation , as follows
use strict;
use warnings;
use utf8;
use Encode;
sub convert_utf8_to_gbk;
sub convert_gbk_to_utf8;
#----------------------------------------------------------
# The main function
#----------------------------------------------------------
my $dir_name = "deal_dir";
unless (-e $dir_name)
{
mkdir $dir_name;
}
my $file_path = "test.m";
convert_utf8_to_gbk($file_path,$dir_name);
#convert_gbk_to_utf8($file_path,$dir_name);
#----------------------------------------------------------
# Subfunctions
#----------------------------------------------------------
sub convert_utf8_to_gbk
{
my $utf8_file = shift;
my $dir_name = shift;
my $gbk_file = $dir_name."/".$utf8_file;
open my $file_rd,'<:encoding(utf8)',$utf8_file;
open my $file_wr,'>:encoding(gbk)',$gbk_file;
while(<$file_rd>)
{
chomp;
print $file_wr $_,"\n";
}
close $file_rd;
close $file_wr;
}
sub convert_gbk_to_utf8
{
my $gbk_file = shift;
my $dir_name = shift;
my $utf8_file = $dir_name."/".$gbk_file;
open my $file_rd,'<:encoding(gbk)',$gbk_file;
open my $file_wr,'>:encoding(utf8)',$utf8_file;
while(<$file_rd>)
{
chomp;
print $file_wr $_,"\n";
}
close $file_rd;
close $file_wr;
}
边栏推荐
- 杰理之触摸按键识别流程【篇】
- 最新海康摄像机、NVR、流媒体服务器、回放取流RTSP地址规则说明[通俗易懂]
- Jenkins打包拉取不到最新的jar包
- 太湖 “中国健康农产品·手机直播万里行”走进太湖
- DEX文件解析 - method_ids解析
- 杰理之触摸按键识别流程【篇】
- QT :QAxObject操作Excel
- 如何快速通过PMP考试?
- 25: Chapter 3: developing pass service: 8: [registration / login] interface: receiving and verifying "mobile number and verification code" parameters; (it is important to know the application scenario
- 如何做好测试用例设计
猜你喜欢

Big God explains open source buff gain strategy live broadcast

Enterprise middle office planning and it architecture microservice transformation

CV+Deep Learning——网络架构Pytorch复现系列——basenets(BackBones)(一)
![Halcon knowledge: check the measurement objects [1]](/img/0a/3a12e281fcb201d8d11b25dac4145a.png)
Halcon knowledge: check the measurement objects [1]

25:第三章:开发通行证服务:8:【注册/登录】接口:接收并校验“手机号和验证码”参数;(重点需要知道【利用redis来暂存数据,获取数据的】的应用场景)(使用到了【@Valid注解】参数校验)

Introduction to neural network (Part 1)

Spark - 一文搞懂 Partitioner

杰理之触摸按键识别流程【篇】

obsidian配合hugo的使用,让markdown本地编辑软件与在线化无缝衔接

Solve the problems of Devops landing in complex environment with various tools with full stack and full function solutions
随机推荐
Jenkins打包拉取不到最新的jar包
C language: hashtable
How unity pulls one of multiple components
【Try to Hack】Windows系统账户安全
Primary school, session 3 - afternoon: Web_ sessionlfi
NLP技能树学习路线-(一)路线总览
TorchDrug--药物属性预测
凌云出海记 | 一零跃动&华为云:共助非洲普惠金融服务
静态类使用@Resource注解注入
【450. 删除二叉搜索树中的节点】
Qt:qaxobject operation Excel
exness:美GDP终值意外加速萎缩1.6%
新出生的机器狗,打滚1小时后自己掌握走路,吴恩达开山大弟子最新成果
最新海康摄像机、NVR、流媒体服务器、回放取流RTSP地址规则说明[通俗易懂]
如何快速通过PMP考试?
Filebeat自定义index和fields
Jerry's determination of detection sensitivity level [chapter]
Filebeat custom indexes and fields
杰理之检测灵敏度级别确定【篇】
Description of the latest RTSP address rules for Hikvision camera, NVR, streaming media server, playback and streaming [easy to understand]