This mysterious incarnation seems to be able to tell the difference:

  sub isnum ($) {
      return 0 if $_[0] eq '';
      $_[0] ^ $_[0] ? 0 : 1
  }

If you want to know why then have a look at this thread:


http://www.perlmonks.org/?node=How%20to%20check%20if%20a%20scalar%20value%20is%20numeric%20or%20string%3F

My brief and cynical summary is that the general perl philosophy is that
there is no difference between 'strings that look like numbers' and
'numbers', however seeing how perl is a bastion of inconsistency, there is
sometimes a difference so it's sometimes important what kind of value you
have, and the above code uses some of those differences to detect what kind
scalar is supplied.

--Rafael



On Fri, May 16, 2014 at 4:46 PM, Darryl L. Pierce <dpie...@redhat.com>wrote:

> On Thu, May 15, 2014 at 01:04:13PM -0400, Ernest Allen wrote:
> > Does proton messenger support sending complex maps as the message body?
> That is, maps whose values are other maps or lists and not just strings?
> >
> > When I send a message and the body is encoded as qpid::proton::MAP, the
> map values appear to have been converted to strings.
> >
> > For example (in perl)
> >
> > In the sender
> > $msg->set_body({"foo" => 2, "bar" => [3]}, qpid::proton::MAP);
> >
> > In the receiver when I dump the body, I'm getting
> >  $VAR1 = \{
> >             'bar' => 'ARRAY(0xa2aad0)',
> >             'foo' => '2'
> >           };
> >
> > It appears that the array has been converted to the string
> 'ARRAY(0x...)'. And the 2 is now a string '2'.
> > I don't think this is just the way the receiver is dumping the message
> body as I'm not able to convert the results to the expected type or
> variable.
> >
> > When I send a perl HASH instead of an array as one of the values, it is
> coming through as the string'HASH(0x....)'.
>
> This should now be fixed on trunk. I've updated the recv.pl example to
> display the full body of received messages to verify that all values are
> being passed.
>
> Now, that being said, there's a caveat with Perl. Since there's no way
> for Perl to determine what any scalar value is (beyond the class name
> for blessed objects) everything has to be inserted into the data object
> as a string. So, for example, if you put the following into the body of
> a message in Perl:
>
>   $msg->set_body({"fibonacci" => [1, 1, 2, 3, 5, 8, 13]});
>
> then the receive will get:
>
>   {"fibonacci" => ["1", "1", "2", "3", "5", "8", "13"]}
>
> I'll continue to look for some way to improve this, but for now at least
> the structure of complex hashes and arrays are preserved in Perl.
>
> --
> Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc.
> Delivering value year after year.
> Red Hat ranks #1 in value among software vendors.
> http://www.redhat.com/promo/vendor/
>
>

Reply via email to