>>451>>452 Perl5、バイナリコード(ln)を含むデータをファイルから読み込み、変換》逆変換
undef $/; # slurp
$s = <>;
@b = map{qw(ヒ タ)[$_]} split'', unpack 'B*', $s;
print @b, "\n";
%h = qw(ヒ 0 タ 1);
$t = pack 'B*', join '', map{$h{$_}} @b;
print $t;
実行結果
$ od -xc Hello_world_ln.txt
0000000 6548 6c6c 206f 6f77 6c72 0a64
H e l l o w o r l d \n
$ cat Hello_world_ln.txt
Hello world
$ perl 18_443_444_ヒタ.pl < Hello_world_ln.txt
ヒタヒヒタヒヒヒヒタタヒヒタヒタヒタタヒタタヒヒヒタタヒタタヒヒヒタタヒタタタタヒヒタヒヒヒヒヒヒタタタヒタタタヒタタヒタタタタヒタタタヒヒタヒヒタタヒタタヒヒヒタタヒヒタヒヒヒヒヒヒタヒタヒ
Hello world