system stack: AMD64 hardware
Debian 11 linux
MATE desktop & terminal
println("What is your name?")
name2 = readln();
println( "Welcome to Julia $name2")
What is your name?
ERROR: LoadError: UndefVarError: readln not defined in Main
Suggestion: check for spelling errors or missing imports.
Stacktrace:
[1] top-level scope
@ ~/Julia26/HelloJulia2.jl:7
[2] include(mod::Module, _path::String)
@ Base ./Base.jl:306
[3] exec_options(opts::Base.JLOptions)
@ Base ./client.jl:317
[4] _start()
@ Base ./client.jl:550
in expression starting at /home/wwink9/Julia26/HelloJulia2.jl:7
Hi @dave3897, welcome to the forum. You’re looking for readline, not readln:
help?> readline
search: readline readlines readlink eachline readdir @inline real hardlink
readline(io::IO=stdin; keep::Bool=false)
readline(filename::AbstractString; keep::Bool=false)
Read a single line of text from the given I/O stream or file (defaults to
stdin). When reading from a file, the text is assumed to be encoded in
UTF-8. Lines in the input end with '\n' or "\r\n" or the end of an input
stream. When keep is false (as it is by default), these trailing newline
characters are removed from the line before it is returned. When keep is
true, they are returned as part of the line.
Return a String. See also copyline to instead write in-place to another
stream (which can be a preallocated IOBuffer).
See also readuntil for reading until more general delimiters.
Examples
≡≡≡≡≡≡≡≡
julia> write("my_file.txt", "JuliaLang is a GitHub organization.\nIt has many members.\n");
julia> readline("my_file.txt")
"JuliaLang is a GitHub organization."
julia> readline("my_file.txt", keep=true)
"JuliaLang is a GitHub organization.\n"
julia> rm("my_file.txt")
julia> print("Enter your name: ")
Enter your name:
julia> your_name = readline()
Logan
"Logan"