| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Data::HexDump; |
| 6 |
use FileHandle; |
| 7 |
|
| 8 |
my $prgname = "hexdump"; |
| 9 |
my $file = shift; |
| 10 |
my $fh; |
| 11 |
|
| 12 |
if ($file) { |
| 13 |
die "$prgname: $file: Is a directory\n" if -d $file; |
| 14 |
$fh = new FileHandle $file; |
| 15 |
die "$prgname: $file: $!\n" unless defined $fh; |
| 16 |
|
| 17 |
my $f = new Data::HexDump; |
| 18 |
$f->fh($fh); |
| 19 |
$f->block_size(1024); |
| 20 |
print while $_ = $f->dump; |
| 21 |
|
| 22 |
close $fh; |
| 23 |
} |
| 24 |
else { |
| 25 |
# read STDIN |
| 26 |
} |
| 27 |
|
| 28 |
sub Usage { |
| 29 |
die "Usage: $prgname [FILE]\n" . |
| 30 |
"Dump FILE, or standard input, to standard output.\n\n" . |
| 31 |
"With no FILE, or when FILE is -, read standard input.\n"; |
| 32 |
} |