ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> visualperl-discuss
visualperl-discuss
[Visualperl-discuss] RE: How to return a Boolean from Perl to C#
by Fowler, Jim (EDS) other posts by this author
Mar 4 2004 8:34PM messages near this date
view in the new Beta List Site
Re: [Visualperl-discuss] Visual Perl breakpoint conditions | [Visualperl-discuss] How to return a Boolean from Perl to C#
Thanks.  I must have had something else in there that was throwing it off.
It works fine now.

Thanks again,

Jim Fowler
EDS@Weyerhaeuser Business Process Automation Group
jim.fowler@[...].com
253-924-2356

-----Original Message-----
From: Jan Dubois [mailto:jand@[...].com] 
Sent: Thursday, March 04, 2004 12:10 PM
To: Fowler, Jim (EDS)
Cc: perl.net@listserv.ActiveState.com;
visualperl-discuss@[...].com
Subject: Re: How to return a Boolean from Perl to C#

On Thu, 4 Mar 2004 09:38:39 -0800 , "Fowler, Jim (EDS)"
<jim.fowler@[...].com>  wrote:

> How do I return true or false to C# from PERL.  If I define the method as
> returning a bool it will not accept a 1 or 0 as true or false, it wants the
> actual .Net Boolean type.  How do I do that?

You must be doing something wrong.  PerlNET automatically translates the
Perl bool semantics to .NET System.Boolean types whenever you declare
the return type as boolean.  For example:

# ===== MyBool.pl =====
package MyBool;

=for interface
    bool returns_true();
    bool returns_false();
=cut

sub returns_true  { 1 }
sub returns_false { 0 }

// ===== test.cs =====
class Test {
    static void Main() {
        MyBool obj = new MyBool();
        if (obj.returns_true())
            System.Console.WriteLine("returns true");
        if (!obj.returns_false())
            System.Console.WriteLine("returns false");
    }
}

Compiling and running it:

  plc --target library MyBool.pl
  csc test.cs -r:MyBool.dll
  test

prints:

  returns true
  returns false

If the Perl value is undef, 0 or "" then it will be converted to false,
otherwise it will become true.

Cheers,
-Jan
_______________________________________________
VisualPerl-discuss mailing list
VisualPerl-discuss@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved