learingperl01
MIS
Hello all,
pretty new to unpack function in Perl. I am trying to take an input file read it and use unpack to create a HEX output of the entire file. The only problem is that when I compare the HEX values of the file I am reading with the output of unpack some of the value are not correct, for some reason some hex values are off.
Example:
if my in file viewed in a HEX viewer shows the first the 8 bytes as 19 00 1d 12 33 0d 0a 00
The output of the unpack are shown as
19 00 1d 12 33 65 44 32
I was wondering if someone could let me know if I am going at this the correct way or if I am missing something in my code that maybe converting certain bytes incorrectly.
Thanks,
pretty new to unpack function in Perl. I am trying to take an input file read it and use unpack to create a HEX output of the entire file. The only problem is that when I compare the HEX values of the file I am reading with the output of unpack some of the value are not correct, for some reason some hex values are off.
Example:
if my in file viewed in a HEX viewer shows the first the 8 bytes as 19 00 1d 12 33 0d 0a 00
The output of the unpack are shown as
19 00 1d 12 33 65 44 32
I was wondering if someone could let me know if I am going at this the correct way or if I am missing something in my code that maybe converting certain bytes incorrectly.
Thanks,
Code:
#!/usr/bin/perl
use strict;
use warnings;
my($strInputFile) = $ARGV[0];
if ($#ARGV ne "0")
{
print "\n";
print "Usage:\n";
print "bin_hex.pl filename\n";
exit;
}
if (open(INPUTFILE, "< $strInputFile"))
{
binmode(INPUTFILE);
while (<INPUTFILE>)
{
my $strBytes = $_;
print unpack("H32", $strBytes);
}
close(INPUTFILE);
}
else
{
print "ERROR! Cannot open file $strInputFile\n";
}