Created
June 17, 2015 19:28
-
-
Save joebo/c0c56f41c610eb04370b to your computer and use it in GitHub Desktop.
picat reading a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% exmaple reading a file | |
import util. | |
main => | |
writeTest, | |
readTest. | |
randBetween(Lower,Upper)=Num => Num=floor(frand()*(Upper-Lower+1)+Lower). | |
writeTest => | |
Lines=1..5, | |
OutputFile = open("output.txt",write), | |
foreach(Line in Lines) | |
Text=[chr(randBetween(65,90)) : I in 1..randBetween(5,20)], | |
writef(OutputFile, "%d\t%s\n", Line,Text) | |
end, | |
close(OutputFile). | |
readTest => | |
Lines = read_file_lines("output.txt"), | |
Arr = new_array(Lines.length,2), | |
foreach(I in 1..Lines.length) | |
Parts = Lines[I].split("\t"), | |
Arr[I,1] = parse_term(Parts[1]), | |
Arr[I,2] = Parts[2] | |
end, | |
write(Arr). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment