Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The Python code doesn't show the value of nRow or from where it is obtained.

And your words:

reading file 05398.bin with size 90942 with nCols 3954 and nRows 23 nCols stays static for all of the files, but nRows changes for each file.

contradicts the evidence of the Python code which has nRow preset (somewhere) and calculates the value of nCols.

But, taking you at your word, and assuming the files consist of N rows of 3954 columns, you could do this:

use constant NCOLS => 3954; my $file = $matrixPath.'/'.$info{$transcriptName}{'PATH'}; my $fileSize = -s $file; die 'Bad filesize' unless $filesize % NCOLS == 0; open IN, $file or die "Can't open inputfile $file $!"; binmode(IN); ## Note: You're reading the whole file in a single read NO NEED FOR A +LOOP. sysread(IN, my $buffer, $fileSize) or die. close IN; ## The first (rightmost) unpack splits the buffer into NCOLS length se +ctions of bytes. ## The second unpack breaks each of those into its individual (uchar) +integers ## and puts them in an anonymous array. ## the map assigns al the anonymous arrays to @matrix. # Update: template corrected, see posts below. my @matrix = map[ unpack 'C*', $_ ], unpack '(a' . NCOLS . ')*', $buff +er; ...

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Unpack an 8 bit unsigned char matrix by BrowserUk
in thread Unpack an 8 bit unsigned char matrix by Ineffectual

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [ovedpo15]: how to fast add "hey" to each element of array. if array=(a,b,c) then array=(ahey,bhey, chey)
    [choroba]: $_ .= 'hey' for @array;

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (5)
    As of 2018-03-24 23:05 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (299 votes). Check out past polls.