Ah. My first real Erlang effort presented for all to see – http://github.com/mmullis/erlang-macaddr.

It started with the goal of porting the macaddr gem for ruby. This is all on R12B-4 so keep that in mind. Macaddr basically runs an os specific command like ifconfig or ipconfig and attempts to extract out the mac address information from the resulting spewage using a regular expression. There’s quite a few posts about how this is not available in Erlang and that the undocumented inet:ifget and inet:getiflist are not really portable. I hope someone finds it useful.

Ok, so it’s nothing hard in Ruby but Erlang ended up being more difficult. Mostly due to the new re module not being quite the same. I also had to break the code up a bit more in order to isolate different aspects. I’m not an Erlang guru either so there’s probably some dumb code in there and optimizations needed.

Two things I learned in the process of dealing with the re module. The first is that it is based on PCRE underneath. To help in debugging, I built the PCRE packakge using the source which is tar.bz2 in the OTP release. PCRE includes a program called pcretest that will let you run regexes with different data. It’s easy enough to figure out. What you do is validate that PCRE is handling a regex the way you want, and then back up into Erlang.

The second thing I learned is that you have to escape ALL backslashed expressions/assertions so that they pass through Erlang unmodified and get to PCRE. I was trying to use “\b” which is word boundary but it never made it down to PCRE correctly untill it hit me and I tried “\\b”. Eureka! (yes, one of my favorite shows).

The doc for re has a really small blurb in the replace function doc. Too hidden for me so I sent a request to the erlang-bugs mailing list to make it really clear.

The real time consumer was that the regex that worked fine on windows and linux broke down on macos where there’s a much longer sequence of “nn:”. This resulted in the exporting of an internal function so I could test it more readily.

Overall, I think it took longer than I would like a small project to take but I’m picky and wanted to make it reasonably complete with Makefile, eunit tests, git hosting on github, Readme, edoc, clean dialyzer, testing on 3 different platforms (Linux, Windows Vista, and Mac OSX). It should be a decent structure for my next project.