Handling matcherror

I am processing line of a file that have module info
some have a .extension, and some dont
I am in need of the best way to handle the matcherror on those that dont
to report an error and continue processing

modis = “xxxxx.txt”
[modsplit, modspltext] = String.split(modis, “.”, parts: 2 )

splits modis in 2 parts [“xxxxx”, “txt”]

when modis = “xxxxxx”
[modsplit, modspltext] = String.split(modis, “.”, parts: 2 )

gets a matcherror

Thanks

case String.split(modis, ".", parts: 2) do
  [modsplit, modspltext] -> 
    IO.puts "with extension"
  [modsplit] ->
    IO.puts "without extension"
end

or

split = String.split(modis, ".", parts: 2)
process_split(split)

def process_slit([modsplit, modspltext]),
  do: IO.puts "with extension"
def process_slit([modsplit]),
  do: IO.puts "without extension"

Thanks so much for the help!!

Regards
Bryan

1 Like