I think that you are going about this in a too C-ish manner. Whenever I encounter a problem where Perl seems to be getting in the way, I tend to find that I'm using the wrong method and by looking around, there is a perlish method or function that addresses the problem.
In this case, you need vec.
#! perl -slw use strict; sub xformBits { my( $in ) = shift; my $out = chr(0) x length( $in ); vec($out,$_,1) = vec($in,7-int($_/8)+8*(7-$_%8),1) for 0..63; return $out; } my $example = 'ABCDEFGH'; print "Input: $example"; print join ' ', split'', unpack 'B8', $_ for split '', $example; my $xformed = xformBits $example; print "\nOutput: $xformed"; print join ' ', split'', unpack 'B8', $_ for split '', $xformed; __END__ [12:12:24.25] P:\test>414344 Input: ABCDEFGH 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 1 0 0 1 0 0 0 1 1 1 0 1 0 0 1 0 0 0 Output: ??f¬ 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 [12:12:49.51] P:\test>
In reply to Re: perl bit matrix transposition / weak typing problem
by BrowserUk
in thread perl bit matrix transposition / weak typing problem
by infi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |