Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试创建一个名称基于函数的整数值的文件,显然下面不起作用,但给了你这个想法:
getValue() -> 1. createFile() -> {ok, File} = file:open( getValue(), [write]), io:format(File,"Test~n"), file:close(File).
这应该很简单,即使 Erlangs 缺乏对字符串的支持,所以我一定只是遗漏了一些明显的东西(就像新事物的代价一样):
如果您只想打开一个名称为“1”的文件,那么您可以使用它integer_to_list/1来执行此操作(因为字符串只是字符的 ASCII 值的整数列表):
integer_to_list/1
getValue() -> 1. .... {ok, File} = file:open(integer_to_list(getValue()), [write]),
如果您想根据 from 的值创建文件名getValue/0,则适用相同的原则,但您只需通过将多个列表粘合在一起来创建文件名。
getValue/0