in reply to how to get Perl hash in C#

Have your Perl program dump the output as JSON (use either JSON, JSON::MaybeXS, JSON::Tiny, or JSON::PP - the last of which comes out of the box with recent versions of Perl) either to STDOUT or to a temporary file.

Then get your C# program to read the JSON and parse it. (There are several JSON libraries for C# listed on json.org.)

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Replies are listed 'Best First'.
Re^2: how to get Perl hash in C#
by Hossein (Acolyte) on Jan 24, 2014 at 13:03 UTC
    OK,

    When I try to run this:

    my $JSON = JSON->new->utf8; $JSON->convert_blessed(1); $JSON->allow_blessed(1); $JSON->pretty(1); my $json = $JSON->encode(\%arr_hash); print "JSON [\n $json\n ]\n";
    I only get the root level data and the rest are null!
    JSON [ { "ace_context" : [ null, null, null, null, null, null, null, null ], "server_nmap" : [ null, null, ... null ] }
    Same thing happends when I try this:
    my $json = $JSON->encode(\@ace_context);
    BUT when I run this:

    print Dumper(\%arr_hash);

    the output contains everything.

    How the JSON code should look like in order to "export" everything to JSON-format data?

      What is this "everything" that appears in the Data::Dumper output? Is it stuff that would be nonsensical in JSON output? (e.g. coderefs, pointers to open file handles, etc)

      use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
        Hi,

        Tha hash values are arrays. These arrays can contain some hash too. Below is the output from Data::Dumper.

        I need these values imported av hash/"collection" in C#

        $VAR1 = bless( { 'INTERFACE' => [ undef, 'vlanX' ], 'LOCATION' => 'X3', 'ACELOGICAL' => 'user', 'CHILD' => [ bless( { 'IPROUTE' => '0.0.0.0 0.0.0.0 x +xx.xxx.x.x.', 'NAME' => 'vlanX', 'ACE' => 'ACEx', 'CHILD' => [ bless( { 'IPROUTE' + => undef, 'NAME' => 'name', 'INTERFACE' => 'vlanX', 'ACE' => undef, 'SERVERFARM' => undef, 'CHILD' => [], 'OSID' => [], 'ALIAS' => undef, 'OBJECTID' => undef, 'PARENT' => [ $VAR1->{'CHILD'}[0] ], 'MASTERSHAPE' => 'ACE_RSERVER', 'CONTEXT' => 'Cntext', 'SHAPEID' => [], 'IPADDRESS' => 'xxx.xxx.x.xx' }, 'some value' ), 'IPROUTE' + => undef, 'NAME' => 'name', 'INTERFACE' => 'vlanX', 'ACE' => undef, 'SERVERFARM' => undef, 'CHILD' => [], 'OSID' => [], 'ALIAS' => undef, 'OBJECTID' => undef, 'PARENT' => [ $VAR1->{'CHILD'}[0] ], 'MASTERSHAPE' => 'ACE', 'CONTEXT' => 'some value ', 'SHAPEID' => [], 'IPADDRESS' => 'xxx.xxx.x.xx' }, 'some value' ), . . .