in reply to Binary file handling

To answer your exact question pack() and unpack() will let you read and write doubles. Look it up in your favorite Perl book, do a search here, then try testing things in the debugger.

If you are writing binary files you should use binmode() like:

open(BINM,"<:raw"); binmode(BINM); read(BINM,$number,64);

It will not have any effect if you don't need it but will save your bacon if you do.

If your matrix is too big for your system's memory then I would have thought that doing things via files would take way too long. I would suggest that a carefull examination of the problem you are trying to solve is in order.

If you still want to transpose in files remember that there are many ways to do it, for example if you split the matrix into four quarters, transpose each of them and then combine them in the right order you may find that efficiency can be improved. This problem is the same as reflecting a bitmap image around a diagonal, I'll bet that some of the image processing books have some neat tricks you should look at (the last time I did any low level raster stuff was almost 10 years ago).

Replies are listed 'Best First'.
Re:^2 Binary file handling
by Hena (Friar) on Mar 18, 2004 at 09:51 UTC
    Well the problem with pack comes from using 'nan' and 'inf' there. Now basicly with pure numbers, i could:
    # packing $str=pack ("d*",@numbers); # unpacking to a correct column $val=(unpack("d*",$str))[$col];
    But that wont work if there is 'nan' in the @numbers array, will it?

    I quess i could save memory by use pack in read loop. Thus pushing the limit back to a point. But i have to think that splitting.