making a meal out of hashing

M

Mark D Smith

Hi

I have to pass some data to an API as a hash. ok i know the data sent is ok
but i cannot seem to decode the reply

$menuitems
{
'oranges' => {},
}

my $result = $shop->stockstatus( $menuitems );


response is a hash in this format (or that's what the API readme says.

$menuitems
{
'oranges' =>
{
'result' => 'NOT AVAILABLE',
'message' => 'Out of Season'
}
}

How do i access 'result' or 'message', and is there an easy way for
debugging to print the hash.

Mark
 
P

Paul Lalli

Mark said:
I have to pass some data to an API as a hash. ok i know the data sent is ok
but i cannot seem to decode the reply

$menuitems
{
'oranges' => {},
}

I don't know what you think this code is doing, but I'm willing to bet
that it's not what it's actually doing.

Perhaps you missed the = operator, to assign the hashref { 'oranges'=>
{} } to the variable $menuitems?
my $result = $shop->stockstatus( $menuitems );


response is a hash in this format (or that's what the API readme says.

$menuitems
{
'oranges' =>
{
'result' => 'NOT AVAILABLE',
'message' => 'Out of Season'
}
}

How do i access 'result' or 'message',

making the same assumption as above, that $menuitems is assigned to the
hashref below it,
print "Result: $menuitems->{oranges}{result}\n";
print "Message: $menuitems->{oranges}{message}\n";

You should read up on references and multi-dimensional data structures:
perldoc perlreftut
perldoc perlref
perldoc perllol
perldoc perldsc
and is there an easy way for debugging to print the hash.

use Data::Dumper;
print Dumper($menuitems);

Paul Lalli
 
M

Mark D Smith

making the same assumption as above, that $menuitems is assigned to the
hashref below it,
print "Result: $menuitems->{oranges}{result}\n";
print "Message: $menuitems->{oranges}{message}\n";

You should read up on references and multi-dimensional data structures:
perldoc perlreftut
perldoc perlref
perldoc perllol
perldoc perldsc


use Data::Dumper;
print Dumper($menuitems);

Paul Lalli

thanks for the input, yes there are a few errors as i typed while on the
phone.

Data::Dumper; gives me more clues.

and now i know the right perldocs i go do some reading.

Mark
 
M

Mark D Smith

A. Sinan Unur said:
[email protected]:



If you are not willing to put any effort into helping others help you, why
do you think we should put any effort into helping you?

Sinan

PS: *PLONK*

Fair comment no excuses.
I have used this group before and always had good answers so i don't want to
be plonked by too many users.

as I've been added to Sinan's PLONK file this is for others in the group.

guess i should have added relative newbie to perl.

Mark
 
P

Paul Lalli

Mark said:
as I've been added to Sinan's PLONK file this is for others in the group.

guess i should have added relative newbie to perl.

Absolutely not. Being new to Perl is wholly irrelevant. There is no
way that is an excuse for not following the Posting Guidelines, or for
not making a minimal amount of effort to help us help you.

Paul Lalli
 
T

Tad McClellan

Mark D Smith said:
I have used this group before and always had good answers so i don't want to
be plonked by too many users.

as I've been added to Sinan's PLONK file this is for others in the group.


It is possible, even likely, that you've been added to other's as well.

guess i should have added relative newbie to perl.


Why would that be relevant?

We are not talking about a Perl issue, we are talking about a
Usenet issue (respect for other people's time).

So, "newbie to usenet" would have been relevant, but not accurate, as
you said you've been here before.

If you use up all of your coupons frivolously, then you might have run
out when you really need them...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,489
Latest member
BrigidaD91

Latest Threads

Top