• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

PERL help opening a hex file

I have a .dat file that I need to read into a perl program. If I look at this file in ultraedit it is just a bunch of hex. I need to read each hex number into an array so that I can later rearrange and convert to decimal. for example:

000002AA08 would read in as

@array[0] = 00
@array[1] = 00
@array[2] = 02
@array[3] = AA
@array[4] = 08


is this possible? what I have done so far is below but it just prints me out a bunch of garbage. i know right now it is only reading into a string but i need to get the string correct before i can break into an array, i believe. any help here would be greatly appreciated.

#!/usr/bin/perl

$nabl_stand_file="fat1r1.dat";
open(nabl_standr, $nabl_stand_file) || die("Could not open file!");
$string_nabl=<nabl_standr>;
close(nabl_standr);

print ($string_nabl);



 
Is your file actually hex, or is it an ascii representation of hex (i.e., is the hex value 00 reading in as 00, or as 30, 30 (hex value for an ascii zero, twice)

If it's an actual hex file, and you're reading in 8bit values, you can do something like this:
$array[0] = ord(getc FILEHANDLE);

That will let you skip the conversion to hex altogether, and you'll get a decimal value between 0 and 255.

BTW, @array[$index] is wrong, use $array[$index] 🙂
 
Back
Top