Reading BInary file.
Hello Perl Gurus.
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.
Please help.
jis
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Reading BInary file.
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 [at] hex = map unpack( 'H2', $_ ), split //, <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-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Reading BInary file.
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 [at] hex = map unpack( 'H2', $_ ), split //, <FILE>;
Or more simply as:
local $/;
my [at] 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-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/