<?xml version="1.0" encoding="windows-1252"?>
<node id="46188" title="HexView" created="2000-12-11 23:17:41" updated="2005-07-19 14:08:39">
<type id="1748">
sourcecode</type>
<author id="16834">
OeufMayo</author>
<data>
<field name="doctext">
&lt;code&gt;
package HexView;
use strict;
use warnings;

BEGIN {
	use Exporter ();
	our ($VERSION, @ISA, @EXPORT);
	$VERSION = 0.01;
	@ISA = qw(Exporter);
	@EXPORT = qw(&amp;HexView);
}

sub HexView {
	my $data = shift;
	# If a filehandle  ref was an arg we convert
	# it to an array (in a rather ugly fashion)
 	if (ref($data) eq 'GLOB') {
			@_ = &lt;$data&gt;;
			undef $data;	# clean the 'GLOB(0x123456)'
	}
	while (@_){$data .= shift}

	my ($hex, $char);
	foreach (split (//,$data)){
		$hex  .= sprintf('%02X ', ord($_));
		$char .= ord($_) &gt; 13 ? $_ : ".";
	}

local $: = ''; # a.k.a $FORMAT_LINE_BREAK_CHARACTERS (and we don't want that)
my $formathead =&lt;&lt;"HEAD";
format =
+--------------------------------------------------+------------------+
| 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F  | 0123456789ABCDEF |
+--------------------------------------------------+------------------+
HEAD
my $formatline = &lt;&lt;'LINE';
| ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; | ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; |
 $hex,                                             $char,
LINE
my $formatend = &lt;&lt;'END';
+--------------------------------------------------+------------------+
.
END
eval($formathead . $formatline x (int(length($data)/16)+1) . $formatend);
write;
return 1;
}

1;
&lt;/code&gt;</field>
<field name="codedescription">
&lt;p&gt;A nice and simple Hexadecimal viewer module, using the Perl format functions.&lt;/p&gt;
&lt;p&gt;One cool use in a on-liner:&lt;/p&gt;
&lt;pre&gt;perl -MHexView -e "HexView(\*STDIN)" &lt; some_file&lt;/pre&gt;

&lt;p&gt;you can also use it like this:&lt;/p&gt;
&lt;pre&gt;
HexView($any_scalar);
HexView(@some_array);
HexView(\*FH_REF);
&lt;/pre&gt;

</field>
<field name="codecategory">
Utility Script</field>
<field name="codeauthor">
OeufMayo</field>
</data>
</node>
