Wednesday, July 06, 2005

Monad

I was reading a blog from a guy on the Monad team and saw this snippet. Monad (or MSH) is the next command-line from Microsoft. It's a dynamic scripting language. It reminds me of some sort of mix of Bash, PHP, Perl and .NET. I just had my ah-ha moment:

foreach ($f in $feeds) { 

    #snip..

    # read the content from $feeduri as XML 

    $wc = new-object System.Net.WebClient 
    $s = $wc.OpenRead($feeduri) 
    $sr = new-object System.IO.StreamReader($s) 
    $rssdata = [xml]$sr.ReadToEnd() 

    # display title 
    write-host $rssdata.rss.channel.title

    # display title and date of each item 

    $rssx.rss.channel.item | 
        foreach-object { 
            write-host "-" $_.title 
            write-host "     " $_.pubDate 
        } 

}

Look at how Monad allows you to use .NET objects. Also note the implicit xml support; you can navigate the DOM as if it were an object ($rssdata.rss.channel.title). Very cool.

No comments: