Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!


Forgot your password?
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.");
                } // 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);

Mirrors should reflect a little before throwing back images. -- Jean Cocteau