USPS XML shipping response: if you request all available services for a package, you get something like
$data = {
'Package' => {
'ID' => '0',
'ZipDestination' => '10022',
'Ounces' => '0',
'Postage' => [
{
'Rate' => '41.30',
'MailService' => 'Express Mail PO to Addressee'
},
{
'Rate' => '14.40',
'MailService' => 'Express Mail Flat Rate Envelope (12.5" x 9.5")'
}
],
'ZipOrigination' => '12345',
'Zone' => '8',
'Error' => {},
'Size' => 'REGULAR',
'Pounds' => '11',
'Machinable' => 'FALSE'
}
};
Note the bolded, this is an array to parse as in
foreach $e (@{$data->{Package}->{Postage}}) {
push (@rates, ($e->{Rate} * $num_boxes));
push (@mail, $e->{MailService});
}
So I have two neat arrays of rates and services to display.
The problem: Sometimes there is only one service available:
$data = {
'Package' => {
'ID' => '0',
'ZipDestination' => '12345',
'Ounces' => '8',
'Postage' => {
'Rate' => '127.24',
'MailService' => 'Parcel Post'
},
'ZipOrigination' => '12345',
'Zone' => '8',
'Error' => {},
'Size' => 'OVERSIZE',
'Pounds' => '62',
'Machinable' => 'FALSE'
}
};