-->
本来呢想试着使用MP3::Tag::ID3v2查看mp3文件中的标签信息,可是自显示出来的都是乱码
[root@supersun zsh]# ./id3.pl 潘朵拉.mp3
2: Track number/Position in set
寮???舵兜: Lead performer(s)/Soloist(s)
娼???垫??: Title/songname/content description
????掳庐: Year
Other: Content type
[root@supersun zsh]# cat id3.pl
#!/usr/bin/perl -w
use strict;
use MP3::Tag;
my $file=shift;
my $mp3=MP3::Tag->new($file);
$mp3->get_tags();
my $id3v2 = $mp3->{ID3v2} if exists $mp3->{ID3v2};
my $frameIDs_hash = $id3v2->get_frame_ids('truename');
foreach my $frame (keys %$frameIDs_hash) {
my ($name, @info) = $id3v2->get_frame($frame);
for my $info (@info) {
if (ref $info) {
print "$name ($frame):\n";
while(my ($key,$val)=each %$info) {
print " * $key => $val\n";
}
} else {
print "$name: $info\n";
}
}
}网上查了一下才知道需要用Encode模块进行编码转换,刚好想起还有几个是utf-8编码的文本文件没有转换成gb2312,随便学一下:
#!/usr/bin/perl -w
use strict;
use Encode;
use Encode::CN;
my $file=shift;
my $wfile=shift;
open RFD,"<$file";
open WFD,">$wfile";
my @content=<RFD>;
foreach my $util (@content)
{
$util=encode("euc-cn",decode_utf8($util));
print WFD "$util";
}
close RFD;
close WFD;
[root@supersun note]# cat head.txt
head [OPTION] file
???椤规??:
-c [-]n ??剧ず???n涓?瀛???? 濡???????"-"?????剧ず??ゅ????灏?n瀛?????????????????瀹
-n [-]n ??剧ず???n琛? 濡???????"-"????????灏鹃??n琛???跺??剧ず????????朵?????琛?
-q ???浣?澶????浠舵?朵??瑕???剧ず???浠跺??
-v ??绘????剧ず???浣????浠剁?????浠跺??
??ㄤ娇???-c???椤圭????跺??n?????奸?や????板??澶?锛?涓??互浣跨??: b=512 k=1034 m=1024*1024
[root@supersun note]# ./decode.pl head.txt he.txt
[root@supersun note]# cat he.txt
head [OPTION] file
选项有:
-c [-]n 显示前n个字节 如果有"-"则显示除去节尾n字节后的所有内容
-n [-]n 显示前n行 如果有"-"则截去尾部n行然后显示所有其他的行
-q 操作多文件时不要显示文件名
-v 总是显示操作文件的文件名
在使用-c选项的时候n的取值除了数字外,不可以使用: b=512 k=1034 m=1024*1024

发表评论