Umm, transpose() doesn't return anything. Adding a return pack("C*",@out) makes it do what you want. If it doesn't for you, could you say what perl version you are using? And exactly what you are seeing? "Cries foul" isn't descriptive enough.

Update: another way:

sub transpose { return if length $_[0] < $BUFSIZE; pack"B*",join"",(split//,unpack"B*",substr$_[0],0,$BUFSIZE)[map$_% +$BUFSIZE*$BUFSIZE+int($_/$BUFSIZE),0..$BUFSIZE**2-1] }
Just as background, in case it helps with your problem, note that perl's bitops have two different modes, numeric (where the scalar operands are numbers) and bitwise, where the operands are strings and the operation is done on each bit of each character. The numeric mode is triggered whenever either of the operands was set to a number or has been used in a numeric context. For example, 3|8 is 11, but "3"|"8" is ";". You can force one or the other regardless of where a scalar's been by replacing one of the operands, say $x, with (0+$x) to force numeric mode, or stringize both, so $x^$y becomes "$x"^"$y", to force bitwise mode. See perlop for more info.

In reply to Re: perl bit matrix transposition / weak typing problem by ysth
in thread perl bit matrix transposition / weak typing problem by infi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.