Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Converting scalar value to hash

by philipbailey (Chaplain)
on Sep 21, 2012 at 11:43 UTC ( #994885=note: print w/ replies, xml ) Need Help??


in reply to Converting scalar value to hash

You don't tell us what the argument to your handler subroutine is, although it is evidently an object of some type, as you call a print method on it. Since we do not know what $r is, we can only guess what arguments its print method accepts.

Your code:

$r->print({ 'response' => {'result' => $results,}, });

calls print with a an anonymous hash reference as the sole argument, which appears to have been stringified by that method, and you indicate that is not what you want. Perl does not actually allow hashes to be directly passed as arguments to subroutines: you can either pass a reference to a hash (which didn't have the behaviour you wanted in this case) or provide a list of alternating key/value pairs, which can be turned into a hash by the subroutine (if it is written that way). The latter would look like this:

$r->print(response => {result => $results});

Whether this works for you depends on what exactly the object $r is.


Comment on Re: Converting scalar value to hash
Select or Download Code
Re^2: Converting scalar value to hash
by Anonymous Monk on Sep 22, 2012 at 21:18 UTC

    Well, judging from the subroutine name (sub handler) and the variable $r, I'm betting it's code running under mod_perl and $r is the HTTP request object.

    What's the OP fails to state is how he expects his hash to print. One way or other he needs to serialise it (transform it into a string suitable for outputting). Perhaps Data::Dumper? Storable? But I can't imagine shoving a Perl-style hash to a client to be of much use. Perhaps he wants the hash in one of the markup formats such as XML or YAML or JSON instead?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994885]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-07-13 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (249 votes), past polls