![]() |
構文 |
|
binmode ファイル・ハンドル,レイヤー binmode ファイル・ハンドル |
返り値 |
|
成功時に真(1) |
説明
- 指定したファイル・ハンドルのファイルをバイナリ・モードで扱うようにします。
- レイヤー(I/O層)を指定することで,I/O時の動作を変更することができます。
使用例
#!/usr/bin/perl
use strict;
use warnings;
my $filename = 'data.bat';
open my $fh, "<", $filename or die "$filename:$!";
binmode $fh;
my $data = '';
while (read $fh, my $buf, 4) {
$data .= $buf;
}
close $fh;
#!/usr/bin/perl
use strict;
use warnings;
my $in_file = 'indata.txt'; # 入力ファイル
my $out_file = 'outdata.txt'; # 出力ファイル
my @data = ();
open my $ifh, "<", $in_file or die "$in_file:$!";
binmode $ifh, ":encoding(euc-jp)"; # EUC-JPを指定
@data = <$ifh>;
close $ifh;
open my $ofh, ">", $out_file or die "$out_file:$!";
binmode $ofh, ":utf8"; # UTF-8を指定
print $ofh @data;
close $ofh;
#!/usr/bin/perl
use strict;
use warnings;
binmode STDIN, ":encoding(euc-jp)";
binmode STDOUT, ":utf8";
while (<STDIN>) {
print STDOUT $_;
}