Created
July 5, 2011 17:59
-
-
Save jinie/1065429 to your computer and use it in GitHub Desktop.
Read binary file in perl and print hex output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
my $BLOCK_SIZE=1024; | |
my $fname = $ARGV[0]; | |
open(F,"<$fname") or die("Unable to open file $fname, $!"); | |
binmode(F); | |
my $buf; | |
my $ct=0; | |
while(read(F,$buf,$BLOCK_SIZE,$ct*$BLOCK_SIZE)){ | |
foreach(split(//, $buf)){ | |
printf("0x%02x ",ord($_)); | |
} | |
print "\n"; | |
$ct++; | |
} | |
close(F); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment