November 2017
Beginner
316 pages
6h 40m
English
Now that we have read about filesystem and I/O operations, we can now give a fully fledged example of how a simple Julia script can be created to read and write data into a file.
Here, we have a file named sample.jl, which we have created in the following manner:
# Arguments
in_file = ARGS[1]
out_file = ARGS[2]
# Keeping track using a counter
counter = 0
for line in eachline(in_file)
for word in split(line)
if word == "Julia"
counter += 1
end
end
end
# write the contents to the output file
write(out_file, "the count for julia is $counter")
# read the contents fom the o/p file for user's help
for line in readlines(out_file)
println(line)
end
This script basically takes in two inputs:
Read now
Unlock full access