John W. Krahn wrote:
jis wrote:
Hello Perl Gurus.

Hello,

I have been trying to read BInary file and have not found the best way
to parse it through.
I have been through perl forums and have not found a statisfactory
answer.

Iam trying to read binary file (.bin) and read it to an array in hex
format bytewise.

I have two problems.

1.  Read the file to an array.
2. Reading bytewise to array.

I have used

binmode FILE;
undef $/;
my $data = <FILE>;
close FILE;
my $hex = unpack 'H*', $data;

Now I have got the file in a  scalar variable.
I want to split the variable into an array  where each array index
represents
one 1 byte hex value.

I have tried to use split command. But it takes a long time.and I do
not how to split
byte wise.

local $/;

my @hex = map unpack( 'H2', $_ ), split //, <FILE>;

Or more simply as:

local $/;

my @hex = unpack '(H2)*', <FILE>;



John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to