Hello Monks,

I'm trying to do some matrix handling as fast as possible. Basicly i have a matrix like this
11	12	13
21	22	23
31	32	33
Now i need to transpose that. Originally i just read the whole matrix into memory as transposed arrays and wrote them out. Now this wont work when transposing to big files. Alternative way was to read one column at a time, but this will take a lot of time (perhaps would be faster to read 10 columns into 10 files, then cat them together).

Alternative way would be to read the whole file and write it out in binary format, allowing fast moving in file ((sys)?seek basicly) to get all numbers in correct order, so i can write the result. But how do i handle this?

I could use open, read, print and seek. Assuming that each column holds a double number (64-bits, right):
# loop for reading one column open (BINM,"<:raw"); read (BINM,$number,64); print OUTM "$number\t"; seek (BINM,64*$columns_number,1);
Or i could use sysread, syswrite, sysread and sysseek in similar manner as above. However, when i'm reading the original matrix file.
while (<MATRIX>) { chomp; my @numbers=split (/\t/,$_); # problem }
How do i write it out as doubles, into the binary file? Also if following values are also acceptable, how do they complicate things (case of characters could be set, but i'd prefer them to allow any case):
[+-]?inf NaN

In reply to Binary file handling by Hena

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.