On 11/16/06, Rob Dixon <[EMAIL PROTECTED]> wrote:
Dharshana Eswaran wrote: > > On 11/16/06, Rob Dixon <[EMAIL PROTECTED]> wrote: >> >> Dharshana Eswaran wrote: >>> >>> I am working on the code below: >>> [snip irrelevancies] >>> >>> my @hex = ("14", "2a", "11", "83"); >>> $hex_length = @hex; >>> >>> for($i=0; $i<$hex_length; $i++) { >>> >>> my $binary = unpack 'B*', pack 'H*', $hex[$i]; >>> >>> print "$binary\n\n"; >>> >>> my @fields = unpack 'A2A2A4', $binary; >>> [snip irrelevancies] >>> >>> Now i need to split the binary value of the first element into two halves >>> (A7A1), seecond element into A6A2, third element into A5A3 and so on... >>> >>> Then i need to display the 7bits of the first element, then join 1bit of the >>> first element to the 6bits of the second element(that is join A1 of first >>> element and A6of the second element) and then display it, then join A2 of >>> the second element and A5 of the third element and then display it and so >>> on. >>> >>> How to go bout this? >> >> Does this help? >> >> Rob >> >> >> use strict; >> use warnings; >> >> my @hex = ("14", "2a", "11", "83"); >> my $hex = join '', @hex; >> my $binary = unpack 'B*', pack 'H*', $hex; >> >> my @fields = unpack '(A7)*', $binary; >> print $_, "\n" foreach @fields; >> >> **OUTPUT >> >> 0001010 >> 0001010 >> 1000010 >> 0011000 >> 0011 > > my @fields = unpack '(A7)*', $binary; > > When i tried compiling, it says that > > "Invalid type in unpack: '(' at line 10." > > It does not accept this, i tried other combinations too. But it does not > compile the program. > > What should i do? (Please bottom-post your replies, as it makes long threads like this much easier to understand. Thanks.) Oh dear. It looks like you have an ealier version of Perl where unpack has no sub-templates, altthough I thought it had always been like that. Find out what version you are running (with perl -v) and consider upgrading. I am using v5.8.8 and bmost people use v5.8 or above. In the meantime, replace my @fields = unpack '(A7)*', $binary; with my @fields = $binary =~ /.{1,7}/g; Rob
Thanks Rob. I sincerely want to appreciate your immediate response. It has been a great help for me. Thanks and Regards, Dharshana