当前位置:网站首页>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;
}
边栏推荐
- 如何做好测试用例设计
- Jerry's determination of detection sensitivity level [chapter]
- 操作系统面试题汇总(不定期更新)
- 杰理之关于长按开机检测抬起问题【篇】
- Why should offline stores do new retail?
- Application of JDBC in performance test
- Lambda 表达式原理分析学习(2022.06.23)
- CADD course learning (1) -- basic knowledge of drug design
- Redis ziplist 压缩列表的源码解析
- HeartBeat基于CRM使用NFS对MySQL高可用
猜你喜欢

Enterprise middle office planning and it architecture microservice transformation
Detailed steps for Django to upload excel tables and write data to the database

Halcon知识:盘点一下计量对象【1】

mysql主从同步

消灭Bug,开发者不可不知的几款Bug探索测试神器。

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

NLP skill tree learning route - (I) route overview

The Commission is so high that everyone can participate in the new programmer's partner plan

微信小程序开发实战 云音乐
![Jerry's touch key recognition process [chapter]](/img/3e/bb73c735d0a7c7a26989c65a432dad.png)
Jerry's touch key recognition process [chapter]
随机推荐
暑期实训21组第一周个人工作总结
25:第三章:开发通行证服务:8:【注册/登录】接口:接收并校验“手机号和验证码”参数;(重点需要知道【利用redis来暂存数据,获取数据的】的应用场景)(使用到了【@Valid注解】参数校验)
By analyzing more than 7million R & D needs, it is found that these eight programming languages are the most needed by the industry
The Commission is so high that everyone can participate in the new programmer's partner plan
Playwright - 滚动条操作
Solve the problems of Devops landing in complex environment with various tools with full stack and full function solutions
Go 语言标识符、包名规范
Perl转换文件的编码类型
Client request external interface standard processing method
Halcon knowledge: check the measurement objects [1]
Transport layer uses sliding window to realize flow control
Filebeat custom indexes and fields
Jerry's long press reset [chapter]
QT qstringlist usage
Why should offline stores do new retail?
最新海康摄像机、NVR、流媒体服务器、回放取流RTSP地址规则说明[通俗易懂]
Installation and use of securecrtportable
CADD course learning (2) -- target crystal structure information
Jerry's question about long press boot detection [chapter]
SecureCRTPortable的安装和使用(图文详解)