I am trying to process a text file like a kind of plain text guitar tab with etc. a bit like the Ultimate Guitar Tab site.
Each line will either blanks or chords or lyrics or something like that.
defmodule TextFileProcessor do
def process_file(file_path) do
File.stream!(file_path)
|> Enum.each(&process_line/1)
end
defp process_line(line) when line =~ ~r/^LYRICS:/ do
# Process lines starting with "LYRICS:"
IO.puts("Processing lyrics line: #{line}")
end
defp process_line(line) when line =~ ~r/^CHORDS:/ do
# Process lines starting with "CHORDS:"
IO.puts("Processing chords line: #{line}")
end
defp process_line(line) do
# Default processing for other lines
IO.puts("Processing line: #{line}")
end
end
I can’t use =~ in a guard or other Kernel functions is there a better way to do this?
I hope there is enough in here.
TIA