当前位置:网站首页>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;
}
边栏推荐
- By analyzing more than 7million R & D needs, it is found that these eight programming languages are the most needed by the industry
- MySQL master-slave synchronization
- exness:流动性系列-流动性清洗和反转、决策区间
- QT :QAxObject操作Excel
- Tensorflow2.4 implementation of repvgg
- 最新海康摄像机、NVR、流媒体服务器、回放取流RTSP地址规则说明[通俗易懂]
- NLP skill tree learning route - (I) route overview
- Graduates
- Data intelligence - dtcc2022! China database technology conference is about to open
- Web主机iptables防火墙安全脚本
猜你喜欢

CADD course learning (2) -- target crystal structure information
Source code analysis of redis ziplist compressed list

What is the difference between tolocal8bit and toutf8() in QT

Jenkins打包拉取不到最新的jar包
Redis ziplist 压缩列表的源码解析

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

mysql主从同步

Jenkins can't pull the latest jar package

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

Cv+deep learning network architecture pytoch recurrence series basenets (backbones) (I)
随机推荐
Convert seconds to * * hours * * minutes
Halcon知识:盘点一下计量对象【1】
以全栈全功能解决方案,应对多样工具复杂环境DevOps落地难题
NLP paper lead reading | what about the degradation of text generation model? Simctg tells you the answer
discuz 论坛提速之删除data/log下的xxx.php文件
8 - function
Big God explains open source buff gain strategy live broadcast
The Commission is so high that everyone can participate in the new programmer's partner plan
Notes on modification of Jerry's test box pairing software [chapter]
Build your own website (20)
计网 | 【五 传输层、六 应用层】知识点及例题
大神详解开源 BUFF 增益攻略丨直播
Is it safe to open an account for online stock trading!?
Informatics Olympiad 1362: family problems
Static classes use @resource annotation injection
【Try to Hack】Windows系统账户安全
Solve the problems of Devops landing in complex environment with various tools with full stack and full function solutions
DEX file parsing - Method_ IDS resolution
屏幕显示技术进化史
SQL优化