mirror of
https://gitlab.rlp.net/mobitar/julia_course.git
synced 2024-11-16 13:28:10 +00:00
Use return value of the function in open()
This commit is contained in:
parent
5334e3f8f5
commit
5342da212d
3 changed files with 66 additions and 7 deletions
|
@ -307,17 +307,16 @@ md"""
|
||||||
|
|
||||||
# ╔═╡ 1e75c110-005c-494f-9569-5eca01cb0545
|
# ╔═╡ 1e75c110-005c-494f-9569-5eca01cb0545
|
||||||
begin
|
begin
|
||||||
# Initialize an empty array of the type String
|
|
||||||
# If you just use `[]` without `String`, Julia initializes an empty array with the type `Any` because it can not know what the array will contain.
|
|
||||||
# We did already learn that array with the type `Any` are harmful for performance 🐢
|
|
||||||
lines = String[]
|
|
||||||
|
|
||||||
# Open a file by specifying the path to the file and the mode in which it is opened with.
|
# Open a file by specifying the path to the file and the mode in which it is opened with.
|
||||||
# The mode "r" stands for read-only. This means that we can only read but not change the content of the file.
|
# The mode "r" stands for read-only. This means that we can only read but not change the content of the file.
|
||||||
# For more modes, check the documentation of `open` 📚️
|
# For more modes, check the documentation of `open` 📚️
|
||||||
open("resources/test.txt", "r") do io
|
# The returned value is stored in the variable before `open`
|
||||||
lines = readlines(io)
|
# In this case, the variable `lines` stores a vector of the file lines as strings
|
||||||
|
|
||||||
|
lines = open("resources/test.txt", "r") do io
|
||||||
|
return readlines(io)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The file is automatically closed
|
# The file is automatically closed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
32
Day_4/Day_4.jl
Normal file
32
Day_4/Day_4.jl
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
### A Pluto.jl notebook ###
|
||||||
|
# v0.18.4
|
||||||
|
|
||||||
|
using Markdown
|
||||||
|
using InteractiveUtils
|
||||||
|
|
||||||
|
# ╔═╡ 81b6211e-b065-11ec-0a86-375721c85b07
|
||||||
|
|
||||||
|
|
||||||
|
# ╔═╡ 1fb7d9af-333e-44f2-b693-09ff97937d4c
|
||||||
|
|
||||||
|
|
||||||
|
# ╔═╡ 00000000-0000-0000-0000-000000000001
|
||||||
|
PLUTO_PROJECT_TOML_CONTENTS = """
|
||||||
|
[deps]
|
||||||
|
"""
|
||||||
|
|
||||||
|
# ╔═╡ 00000000-0000-0000-0000-000000000002
|
||||||
|
PLUTO_MANIFEST_TOML_CONTENTS = """
|
||||||
|
# This file is machine-generated - editing it directly is not advised
|
||||||
|
|
||||||
|
julia_version = "1.7.2"
|
||||||
|
manifest_format = "2.0"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
"""
|
||||||
|
|
||||||
|
# ╔═╡ Cell order:
|
||||||
|
# ╠═81b6211e-b065-11ec-0a86-375721c85b07
|
||||||
|
# ╠═1fb7d9af-333e-44f2-b693-09ff97937d4c
|
||||||
|
# ╟─00000000-0000-0000-0000-000000000001
|
||||||
|
# ╟─00000000-0000-0000-0000-000000000002
|
28
Day_4/Tasks_day_4.jl
Normal file
28
Day_4/Tasks_day_4.jl
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
### A Pluto.jl notebook ###
|
||||||
|
# v0.18.4
|
||||||
|
|
||||||
|
using Markdown
|
||||||
|
using InteractiveUtils
|
||||||
|
|
||||||
|
# ╔═╡ 95f0a7c8-b065-11ec-0bd4-a9be6aca0c47
|
||||||
|
|
||||||
|
|
||||||
|
# ╔═╡ 00000000-0000-0000-0000-000000000001
|
||||||
|
PLUTO_PROJECT_TOML_CONTENTS = """
|
||||||
|
[deps]
|
||||||
|
"""
|
||||||
|
|
||||||
|
# ╔═╡ 00000000-0000-0000-0000-000000000002
|
||||||
|
PLUTO_MANIFEST_TOML_CONTENTS = """
|
||||||
|
# This file is machine-generated - editing it directly is not advised
|
||||||
|
|
||||||
|
julia_version = "1.7.2"
|
||||||
|
manifest_format = "2.0"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
"""
|
||||||
|
|
||||||
|
# ╔═╡ Cell order:
|
||||||
|
# ╠═95f0a7c8-b065-11ec-0bd4-a9be6aca0c47
|
||||||
|
# ╟─00000000-0000-0000-0000-000000000001
|
||||||
|
# ╟─00000000-0000-0000-0000-000000000002
|
Loading…
Reference in a new issue