-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWithScope.ex
More file actions
51 lines (38 loc) · 1.03 KB
/
WithScope.ex
File metadata and controls
51 lines (38 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
defmodule WithScope do
@moduledoc """
Documentation for WithScope
"""
@doc """
example
## Examples
iex> WithScope.example
"Now is the time"
"""
def example do
content = "Now is the time"
_lp = with {:ok, file} = File.open("/etc/passwd"),
content = IO.read(file, :all),
:ok = File.close(file),
[_, uid, gid] = Regex.run(~r/games:.*?:(\d+):(\d+)/, content) do
# IO.puts content
"Group: #{ gid}, User: #{uid}"
end
# IO.puts lp
# IO.puts content
content
end
@doc """
example
## Examples
iex> WithScope.example_with_nil
nil
"""
def example_with_nil do
_result = with {:ok, file} = File.open("/etc/passwd"),
content = IO.read(file, :all),
:ok = File.close(file),
[_, uid, gid] <- Regex.run(~r/XXX:.*?:(\d+):(\d+)/, content) do
"Group: #{ gid}, User: #{uid}"
end
end
end