R
RT
Hello,
Hope someone can help me with this question.
I have this binary file (octal dump below):
0000000 0027 c08c 0000 0404 002c 8ce0 0000 0000
0000020 4047 a06c 000b 789d
0000030
It consists of a C structure of
struct {
unsigned int where;
std::string info;
clock_t clock;
timeval time;
}
# BELOW IS THE SNIP OF MY SCRIPT. PLEASE IGNORE THE SYNTAX.
#!/usr/local/bin/perl -w
my $data_file = 'test.bin';
open INFILE, "<$data_file" or die "Unable to open \"$data_file\"\n";
binmode INFILE;
@data = ReadData ($data_file);
sub ReadData
{
my $binary;
if (!(sysread (INFILE, $binary, 24))) { return (); }
# HOW TO UNPACK THE FILE? I KNOW THE TEMPLATE BELOW IS WRONG
return (unpack ("LLLLLL", $binary));
}
My question is how do I unpack the string in the binary file and
display the output? I have read the PACK/UNPACK Perldoc but still
couldn't understand. I would really appreciate your input.
Please response to the group.
Thanks in advance!
-ryan-
Hope someone can help me with this question.
I have this binary file (octal dump below):
0000000 0027 c08c 0000 0404 002c 8ce0 0000 0000
0000020 4047 a06c 000b 789d
0000030
It consists of a C structure of
struct {
unsigned int where;
std::string info;
clock_t clock;
timeval time;
}
# BELOW IS THE SNIP OF MY SCRIPT. PLEASE IGNORE THE SYNTAX.
#!/usr/local/bin/perl -w
my $data_file = 'test.bin';
open INFILE, "<$data_file" or die "Unable to open \"$data_file\"\n";
binmode INFILE;
@data = ReadData ($data_file);
sub ReadData
{
my $binary;
if (!(sysread (INFILE, $binary, 24))) { return (); }
# HOW TO UNPACK THE FILE? I KNOW THE TEMPLATE BELOW IS WRONG
return (unpack ("LLLLLL", $binary));
}
My question is how do I unpack the string in the binary file and
display the output? I have read the PACK/UNPACK Perldoc but still
couldn't understand. I would really appreciate your input.
Please response to the group.
Thanks in advance!
-ryan-