Inline::MonoCS - Use CSharp from Perl, via Mono
use Inline::MonoCS method => "HelloWorld", compiler_args => "", code => <<"CODE"; public class HelloWorld { public static void Main( string[] args) { System.Console.WriteLine( "Hello, " + args[0] + "!" ); } } CODE warn HelloWorld("Frank"); # "Hello, Frank!"
use Inline::MonoCS method => "ProductCount", compiler_args => "-r:System.Data.dll", code => <<'CODE'; using System; using System.Data; using System.Data.SqlClient; public class ProductCount { public static void Main(string[] args) { string connectionString = "Server=111.222.111.222;" + "Database=northwind;" + "User ID=sa;" + "Password=s3cr3t;"; IDbConnection dbcon; using (dbcon = new SqlConnection(connectionString)) { dbcon.Open(); using (IDbCommand dbcmd = dbcon.CreateCommand()) { string sql = "SELECT COUNT(*) AS ProductCount " + "FROM Products"; dbcmd.CommandText = sql; using (IDataReader reader = dbcmd.ExecuteReader()) { while(reader.Read()) { int ProdCount = Convert.ToInt32( reader["ProdCount"] ); Console.WriteLine( ProdCount ); } } } } } } CODE my $count = ProductCount(); warn "We have $count products";
This module provides a simple bridge to execute code written in C# from Perl.
It works by compiling your code, then placing the executable under /tmp/ and exporting a subroutine into the calling package. When you call that exported subroutine, the compiled exe is executed and given your arguments on the command-line.
Whatever your program outputs to STDOUT is considered the return value.
Written by John Drago <jdrago_999@yahoo.com>
This software is Free software and may be used and redistributed under the same terms as perl itself.
To install Inline::MonoCS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Inline::MonoCS
CPAN shell
perl -MCPAN -e shell install Inline::MonoCS
For more information on module installation, please visit the detailed CPAN module installation guide.