- 追加された行はこの色です。
- 削除された行はこの色です。
[[Perl]]
* ツール
**文字コード変換
#!/usr/bin/perl
=head1 DESCRIPTION
文字コードをSJISに
改行コードはCRLFに
=cut
use strict;
use Jcode;
undef $/;
foreach my $path (@ARGV) {
open(IN,"$path")
or warn("can't open $path");
binmode(IN);
my $src = <IN>;
if ($src =~ /\x0D\x0A/) {
# CRLFが存在する
} else {
# CRLFが存在しない
$src =~ s/\x0A/\x0D\x0A/g;
}
$src = &Jcode::convert($src,'sjis');
close(IN);
open(OUT,">$path")
or warn("can't open $path");
binmode(OUT);
print OUT $src;
close(OUT);
}
#!/usr/bin/perl
=head1 DESCRIPTION
文字コードをEUCに
改行コードはLFに
=cut
use strict;
use Jcode;
undef $/;
foreach my $path (@ARGV) {
open(IN,"$path")
or warn("can't open $path");
binmode(IN);
my $src = <IN>;
$src =~ s/\x0D\x0D/\x0A/g;
$src =~ s/\x0D\x0A/\x0A/g;
$src = &Jcode::convert($src,'euc');
close(IN);
open(OUT,">$path")
or warn("can't open $path");
binmode(OUT);
print OUT $src;
close(OUT);
}