Loading ...
Sorry, an error occurred while loading the content.
 

returning complex data structures

Expand Messages
  • Jörg Ziefle
    I am returning a data structure (which is part of a blessed hash) like the following (more than two hierarchy levels) from a module: return $self- {data};
    Message 1 of 2 , Jun 18, 2001
      I am returning a data structure (which is part of a blessed hash) like
      the following (more than two hierarchy levels) from a module:

      return $self->{data};

      should return (from Data::Dumper):

      $VAR1 = {
      'stress' => {
      '1.000000' => '10834259.375000',
      '0.000000' => '23007311.250000',
      '6.000000' => '0.000000',
      '5.000000' => '-17256948.125000',
      '4.000000' => '-25684896.250000',
      '3.000000' => '-13511844.375000',
      '2.000000' => '-1338792.500000'
      },
      'displacement' => {
      '1.000000' => '-0.001805',
      '0.000000' => '-0.000000',
      '6.000000' => '0.000000',
      '5.000000' => '-0.006794',
      '4.000000' => '-0.010326',
      '3.000000' => '-0.009287',
      '2.000000' => '-0.005673'
      }
      };

      When directly returning the data structure from a method (as indicated
      above), I just get the following on the client side:

      $VAR1 = {
      'stress' => {
      },
      'displacement' => {
      }
      };

      that is, the hashed below the second hierarchy level are empty. Btw, I
      get lots of warnings from the daemon:

      Cannot encode 'stress' element as 'hash'. Will be encoded as 'map' instead
      Cannot encode 'displacement' element as 'hash'. Will be encoded as 'map' instead

      If I pass a copy of the data strucure instead, I get the same warnings,
      but I also get the whole data strucure.

      return {%{$self->{data}}};

      Does anybody know what's going on? I would like to directly pass the
      data structure, as the subhashes can be quite big and copying them is
      quite expensive.

      Jörg
    • Paul Kulchenko
      Hi, Jörg! ... As far as I understand, only values of top hash will be copied, not subhashes itself, so it s not so big, but you re right, it should work both
      Message 2 of 2 , Jun 18, 2001
        Hi, J�rg!

        > return {%{$self->{data}}};
        >
        > Does anybody know what's going on? I would like to directly pass
        > the
        > data structure, as the subhashes can be quite big and copying them
        > is quite expensive.
        As far as I understand, only values of top hash will be copied, not
        subhashes itself, so it's not so big, but you're right, it should
        work both ways. In fact, it does work for me and I can reproduce
        described situation.

        > Cannot encode 'stress' element as 'hash'. Will be encoded as 'map'
        > instead
        This warning tell you that you're trying to encode hash, and elements
        can't be encoded as an XML (in your example '1.000000' should become
        a name, which is not allowed). SOAP::Lite supports Map type where
        both key and value encoded as value of elements, so don't have such
        restrictions. Warning tells that SOAP::Lite will use this encoding
        even if you don't ask for it. Shouldn't matter for SOAP::Lite on both
        sides, but other toolkits may not understand it (only ApacheSOAP and
        SOAP4R support it).

        You may switch on debug on client side with on_debug(sub{print@_})
        and compare output with $self->{data} and {%{$self->{data}}}. Send me
        both if it doesn't help you to solve your problem.

        Best wishes, Paul.

        --- J�rg_Ziefle <joerg.ziefle@...> wrote:
        > I am returning a data structure (which is part of a blessed hash)
        > like
        > the following (more than two hierarchy levels) from a module:
        >
        > return $self->{data};
        >
        > should return (from Data::Dumper):
        >
        > $VAR1 = {
        > 'stress' => {
        > '1.000000' => '10834259.375000',
        > '0.000000' => '23007311.250000',
        > '6.000000' => '0.000000',
        > '5.000000' => '-17256948.125000',
        > '4.000000' => '-25684896.250000',
        > '3.000000' => '-13511844.375000',
        > '2.000000' => '-1338792.500000'
        > },
        > 'displacement' => {
        > '1.000000' => '-0.001805',
        > '0.000000' => '-0.000000',
        > '6.000000' => '0.000000',
        > '5.000000' => '-0.006794',
        > '4.000000' => '-0.010326',
        > '3.000000' => '-0.009287',
        > '2.000000' => '-0.005673'
        > }
        > };
        >
        > When directly returning the data structure from a method (as
        > indicated
        > above), I just get the following on the client side:
        >
        > $VAR1 = {
        > 'stress' => {
        > },
        > 'displacement' => {
        > }
        > };
        >
        > that is, the hashed below the second hierarchy level are empty.
        > Btw, I
        > get lots of warnings from the daemon:
        >
        > Cannot encode 'stress' element as 'hash'. Will be encoded as 'map'
        > instead
        > Cannot encode 'displacement' element as 'hash'. Will be encoded as
        > 'map' instead
        >
        > If I pass a copy of the data strucure instead, I get the same
        > warnings,
        > but I also get the whole data strucure.
        >
        > return {%{$self->{data}}};
        >
        > Does anybody know what's going on? I would like to directly pass
        > the
        > data structure, as the subhashes can be quite big and copying them
        > is
        > quite expensive.
        >
        > J�rg
        >
        > To unsubscribe from this group, send an email to:
        > soaplite-unsubscribe@yahoogroups.com
        >
        >
        >
        > Your use of Yahoo! Groups is subject to
        > http://docs.yahoo.com/info/terms/
        >
        >


        __________________________________________________
        Do You Yahoo!?
        Spot the hottest trends in music, movies, and more.
        http://buzz.yahoo.com/
      Your message has been successfully submitted and would be delivered to recipients shortly.