How to replace instances of a word in a string while using Streams

Hello everyone! Help me guys i come from C language programming so on first time my brain exloded.
I ha ve simple target. I have a dump file (its utf8 file) in which i must replace all word “astrakhanzapoved.ru” to “127.0.0.1”. How to do it?
I wrote this code

defmodule Filereader do
	def parse do
		  File.stream!("dump")
        	|> Stream.map(&(IO.inspect(&1)))
		|> Stream.run
	        |>perfomandwrite()
	end
	def perfomandwrite(a) do
			b=Elixir.String.replace(a, "http://astrakhanzapoved.ru", "http://127.0.0.1")
			{:ok, file}=File.open "out", [ :append]
			IO.write file,b
			File.close file
		
	end
end

Its compiled but not work. What i doing wrong?

1 Like

You aren’t executing anything. :slight_smile:

Try adding Filereader.parse() to the end of the file, saving the file as foo.exs, and then running elixir foo.exs.

2 Likes

Keep in mind that Stream.run only returns :ok, so a isn’t going to be what you think it is. You may want to make sure you run through one of the Elixir books.

1 Like