Question

I'm trying to reverse engineer a Julia script from existing Perl code and so far so good, but I've come to a point where I must now write a bunch of binary files in Julia which is something I'm unfamiliar with. I'm wondering if anyone has any experience with that task and, moreover, what the syntax would be. I've scoured the internet but examples have been quite spartan (by spartan I don't mean muscular and prepared for martial conflict but instead barren). If anyone has some sage like wisdom on this topic let me know. If I were writing from dict containing numerical values to a file I would use something like:

for i in sick

f = open("/Users/MacBookPro15/$i/Headaches.dat", "w")
    for x in RICT["$i"]["Headaches"]
        write(f, "$x\n")
    end
close(f)

end

How might I change this to write binary? Thanks so much.

Chase CB

Was it helpful?

Solution

The write function already does write binary data. However, you're explicitly turning your values into strings by interpolating them into a string followed by a newline. It's unclear from this example what kind of values x holds. If x is a Float64, for example, then doing write(f, x) will write it in binary form as eight bytes in your native endianness (typically little endian). On the other hand, if you want to print it in string form, you can use print(f, x) or println(f, x) to print it followed by a newline.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top