简体   繁体   English

如何在erlang中接受来自用户(控制台)的输入

[英]How to accept input from user (console) in erlang

I'm confused How can I accept input from the Erlang shell or eclipse console?我很困惑如何接受来自 Erlang shell 或 eclipse 控制台的输入? I want to accept input for the variable "input" from user.我想接受来自用户的变量“输入”的输入。

p1()->
    io:format(" Codes for business logic of task one \n"),
    spawn(xorgateway, xor_split, []).
xor_split()->
 io:format("enter your decision \n").
   case Value of
         decision1 -> 
            spawn(xorgateway, p2, []);
        decision2 ->
            spawn(xorgateway, p3, []);
        decision3 ->
            spawn(xorgateway, p4, []);
          _->
            io:format("invalid input \n")end.

I'm confused How can I accept input from the Erlang shell我很困惑如何接受来自 Erlang shell 的输入

-module(my).
-compile(export_all).

    get_data() ->
        {ok, Term} = io:read("Enter a number: "),
        io:format("The number you entered plus one is: ~w~n", 
                  [Term + 1]).

In the shell:在外壳中:

8> c(my).        
my.erl:2: Warning: export_all flag enabled - all functions will be exported
{ok,my}

9> my:get_data().
Enter a number: 10.
The number you entered plus one is: 11
ok

10> 

Note that the user needs to enter a period after their input.请注意,用户需要在输入后输入一个句点。 Also, see io:getline() and io:fread()另请参阅io:getline()io:fread()

I want to accept input for the variable "input"我想接受变量“输入”的输入

input is not a variable in Erlang. input不是 Erlang 中的变量。 Erlang variables start with a capital letter. Erlang 变量以大写字母开头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM