[bcn-pm] using Perl;

Victor Jalencas victor at carotena.net
Wed Mar 24 05:10:32 CST 2004


Acabo de veure això a la llista de Mono:

http://charon.ucam.org/mason/software/perl-sharp.html

"Perl# is the result of some days hacking about learning about embedding 
Perl and getting the magic of auto boxing/unboxing working. Now you can 
use Perl modules from C# pretty easily and even write wrappers."

I això seria un exemple:

/*
  * Copyright (C) 2004 Rich Wareham <richwareham at users.sourceforge.net>
  *
  * This file is part of perl-sharp, C# bindings for the perl libraries.
  *
  * perl-sharp is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  *
  * perl-sharp is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
02111-1307, USA
  *
  * $Id$
  */

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

       // Get an instance of the interpreter.
       Interpreter interp = new Perl.Interpreter();
       interp.Embed(); // Do the required magic for Perl to be listening 
to us.

       try {
         // Ensure we have the Mail::IMAPClient package.
         interp.Require("Mail::IMAPClient");

         // Create a new connection
         Console.WriteLine("Logging in, enter server, username and 
password...");
         Perl.Object client = new Perl.Object("Mail::IMAPClient",
             "Server", Console.ReadLine(),
             "User", Console.ReadLine(),
             "Password", Console.ReadLine());

         Console.WriteLine("Fetching subscribed folder list...");
         // Get list of subscribed folders by calling method in
         // Array context
         Scalar[] folders = client.CallArrayMethod("subscribed");

         // List them to STDOUT
         Console.WriteLine("Subscribed to {0} folders:", folders.Length);
         foreach(Scalar folder in folders) {
           Console.WriteLine(" -> {0}", folder);
         }
       } catch( CannotCreateObjectException e ) {
         // If the object couldn't be created, there was an error 
logging in.
         Console.WriteLine("Error logging into server: {0}", e.Message);
       } catch( PerlException e ) {
         // If there is some Perl error, catch it and report.
         Console.WriteLine("{1} was thrown: {0}", e.Message, e.GetType());
       }
     }
   }
}



More information about the Barcelona-pm mailing list