Beta

×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

More perl...

rjw57 (532004) writes | more than 10 years ago

User Journal

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;

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);
            }
        }
    }
}

cancel ×

comment

Slashdot Login

Need an Account?

Forgot your password?
or Connect with...

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>