BlueT has asked for the wisdom of the Perl Monks concerning the following question:

Bcoz of the Frontier cannot return multiple Hashes+Arrays at the same time, so I'm trying to put all arrays and hashes into one %Hash to return.

But, the Hash in Array in Hash doesn't recognized by Frontier,

$data->{content}[1];
should be a Hash ref insdead of a member of the parent array, but Frontier shows it as an array.


How can I force it to be an array?

the following is part of the code in my daemon side program:
#!/usr/bin/perl # # Project A - Parsing engine Template (PeT) # # Author: BlueT <BlueT@BlueT.org> # Since 2007/07 # one PeT for one site, # this Template is for extracting data from tables for specific site. use strict; use warnings; use Frontier::Daemon; my $listen_ip='127.0.0.1'; my $listen_port='5566'; my $d = Frontier::Daemon->new( methods => { extract => \&extract, }, LocalAddr => "$listen_ip", LocalPort => "$listen_port", ); sub extract { my %data = ( site_name => "site name", content => [ # array ref ( # this is [0], a hash ref handicap => [ 0, "asia", "BigSmall" ], A => [ "name", "asia_score", "BigSmall_score" ], B => [ "name", "asia_score", "BigSmall_score" ], ), ( # this is [1] handicap => [ 0, "asia", "BigSmall" ], A => [ "name", "asia_score", "BigSmall_score" ], B => [ "name", "asia_score", "BigSmall_score" ], ), ], ); return \%data; }


Part of my codes in client side is HERE.

The results' HERE.

And i'd reformated the packet content, shown
HERE.

/ BlueT = Matthew / / BlueT@BlueT.org / / Just be Perl Hacking! /

Replies are listed 'Best First'.
Re: send $Hash{$array[%Hash]} using Frontier Question.
by FunkyMonk (Bishop) on Aug 01, 2007 at 11:29 UTC
    ( # this is [0], a hash ref [...] ),

    No, it isn't a hash ref, it's a list. You should use braces { ... } not parentheses to create a hashref:

    my $data = extract(); print $data->{content}->[0]->{A}->[1]; sub extract { my %data = ( site_name => "site name", content => [ # array ref { # this is [0], a hash ref handicap => [ 0, "asia", "BigSmall" ], A => [ "name", "asia_score", "BigSmall_score" ], B => [ "name", "asia_score", "BigSmall_score" ], }, { # this is [1] handicap => [ 0, "asia", "BigSmall" ], A => [ "name", "asia_score", "BigSmall_score" ], B => [ "name", "asia_score", "BigSmall_score" ], }, ], ); return \%data; }

    Output:

    asia_score

      Ooops, it works well after correcting the uncarely () to {}!
      thanx so much! :D
      / BlueT = Matthew / / BlueT@BlueT.org / / Just be Perl Hacking! /