Make that staring at Mono. I have download the Mac OS X distro, played with the sample projects from Mono: A Developer’s Notebook ($16.47 at Amazon), read a couple of articles.
Hmmm… This C# thing looks like a text-based between C, Python and RB, with plenty of curly braces, but sans RB’s IDE
[I mean, try once RB’s IDE, and they’ll pry it away from your dead fingers…]
See this:
// 03-keyfunc/03-regex
using System;
using System.Collections;
using System.IO;
using System.Text.RegularExpressions;
public class ParseHosts {
public static void Main(string [] args) {
string filename;
if (Environment.OSVersion.ToString().StartsWith(”Unix”)) {
filename = string.Format(”{0}etc{0}hosts”,
Path.DirectorySeparatorChar);
} else {
filename = string.Format(”{0}{1}drivers{1}etc{1}hosts”,
Environment.GetFolderPath(Environment.SpecialFolder.System),
Path.DirectorySeparatorChar);
}
if (!File.Exists(filename)) {
Console.Error.WriteLine(”{0} does not exist.”, filename);
Environment.Exit(1);
}
string text;
using (TextReader reader = File.OpenText(filename)) {
text = reader.ReadToEnd();
}
Regex regex =
new Regex(@”(?(\d{1,3}\.){3}\d{1,3})\s+(?(\S+))”);
MatchCollection matches = regex.Matches(text);
foreach (Match match in matches) {
if (match.Length != 0) {
Console.WriteLine(”hostname {0} is mapped to ip address {1}”,
match.Groups[”name”], match.Groups[”ip”]);
}
}
}
}
Nothing really perturbing here, right? In played a little with
monodis
to take a peek at the bytecode. Almost readable.
Hmmmm….