デバッグ時に、バイナリ変数の中身を見たかったので作ってみた
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
{
my $byte1 = "";
my $byte2 = "";
my $byte3 = pack("C*", ord('A'), ord('B'), ord('C')); # 0x41, 0x42, 0x43
for(my $i=0; $i<10; $i++){ $byte1 = $byte1 . pack("C*", $i); }
for(my $i=0; $i<10; $i++){ $byte2 = $byte2 . pack("C*", 0xff - $i); }
# バイナリの連結
my $byte = $byte1 . $byte2 . $byte3;
# Dumperで表示する (バイナリの場合は、うまく画面表示できない)
print Dumper $byte;
BinaryDump($byte);
}
sub BinaryDump {
my ($buf) = @_;
my $len;
my $i;
$len = length($buf);
printf ("length = %d\n", $len);
for ($i = 0; $i < $len; $i++) {
printf("%02X ", ord(substr($buf, $i, 1)));
# 16文字目で画面上の改行
if (($i % 16) == 15) {
print "\n";
}
}
if (($i % 16) != 15) {
print "\n";
}
}