Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
User Journal

Journal rjw57's Journal: More perl...

More wodges of code now. This nicely shows the autoboxing of Scalars and actually does something useful that you /can't/ do easily with the standard .NET framework :).

namespace PerlEmbedExamples {
    using System;
    using Perl;

    class IMAPExample {
        public static void Main(string[] args) {
            Console.WriteLine("Embedding Perl within Mono - IMAP Example");
            Console.WriteLine("(C) 2004 Rich Wareham\n");

            Interpreter interpreter = new Perl.Interpreter();
            interpreter.Embed(); // Do the required magic for Perl to be // sitting listening to us.

            try { // Ensure we have the Mail::IMAPClient package.
                interpreter.Require("Mail::IMAPClient"); // Create a new connection
                Scalar client = interpreter.CallClassMethod("Mail::IMAPClient", "new",
                        "Server", "charon",
                        "User", "rjw57",
                        "Password", "XXXXXXXXX"); // Check for success - autoboxing of Scalars to bools.
                if(!client) {
                    Console.WriteLine("Could not log into server.");
                    return;
                } // Get list of subscribed foderss.
                Scalar[] folders = interpreter.CallMethod(client, "subscribed",
                        Interpreter.CallFlags.ArrayContext); // List them to STDOUT, note autoboxing of Scalars to strings.
                Console.WriteLine("Subscribed to {0} folders:", folders.Length);
                foreach(string folder in folders) {
                    Console.WriteLine(" -> {0}", folder);
                }
            } catch ( PerlException e ) { // If there is some Perl error, catch it and report.
                Console.WriteLine("Error was thrown: {0}", e.Message);
            }
        }
    }
}

I tell them to turn to the study of mathematics, for it is only there that they might escape the lusts of the flesh. -- Thomas Mann, "The Magic Mountain"

Working...