backscratcher

 

hd

Page history last edited by tbarron 1 yr ago

hd

 


#!/usr/bin/perl

$filename = $ARGV[0];

open(IN, "< $filename");

$addr = 0;
$nr = read(IN, $buf, 16);
while (0 < $nr)
{
   printf("%08x: ", $addr);
   $addr += 16;

   for ($i = 0 ; $i < $nr ; $i++)
   {
      $c = substr($buf, $i, 1);
      printf("%02x ", ord($c));
   }

   for ( ; $i < 16 ; $i++)
   {
      print("   ");
   }

   print("  ");

   for ($i = 0 ; $i < $nr ; $i++)
   {
      $c = substr($buf, $i, 1);
      printf("%s", ((0x20 <= ord($c)) && (ord($c) <= 0x7e)) ? $c : ".");
   }

   print("n");

   $nr = read(IN, $buf, 16);
}
close(IN);  

__END__

=head1 NAME

hd - hexdump a file

=head1 SYNOPSIS

  hd <filename>

=head1 DESCRIPTION

This program reads a file and writes its contents to stdout in hex
format. It is based on the Unix utility of the same name.

=head1 AUTHOR

Tom Barron

Comments (0)

You don't have permission to comment on this page.