Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a hash value

Status
Not open for further replies.

kevin197

Programmer
Mar 21, 2002
88
GB
My problem is the same as posted at


However, although the post was very helpfull I still can't pull my data.

So far the perl code I've got is
Code:
#!/usr/bin/perl -w

# include package
use CGI::Carp qw( fatalsToBrowser );
use CGI':standard';
use XML::Simple;
use Data::Dumper;


print "Content-type: text/html\n\n";

$FILENAME = "orders.xml";



my $ref = XMLin($FILENAME, ForceArray => 1);

print Dumper($ref);

print "<br><br><br><br>";

print "$ref->{'xmlns:xsi'}<br>";

$key = 0;

print $doc->{Message}{$key}->{'MessageID'}[0]->{AmazonOrderID}[0];

print "<br>Done";

The
Code:
print Dumper($ref);
shows
Code:
$VAR1 = { 'xmlns:xsi' => '[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance',[/URL] 'Message' => [ { 'MessageID' => [ '1' ], 'OrderReport' => [ { 'FulfillmentData' => [ { 'FulfillmentMethod' => [ 'Ship' ], 'Address' => [ { 'PostalCode' => [ 'cr0 0hx' ], 'StateOrRegion' => [ 'surrey' ], 'PhoneNumber' => [ '07793533558' ], 'AddressFieldOne' => [ '97 godric cres' ], 'City' => [ 'croydon' ], 'Name' => [ 'karen webber' ], 'CountryCode' => [ 'GB' ] } ], 'FulfillmentServiceLevel' => [ 'Standard' ] } ], 'OrderDate' => [ '2007-12-15T08:03:26-08:00' ], 'AmazonOrderID' => [ '203-4034021-8454761' ], 'Item' => [ { 'ItemPrice' => [ { 'Component' => [ { 'Amount' => [ { 'currency' => 'GBP', 'content' => '29.99' } ], 'Type' => [ 'Principal' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '3.95' } ], 'Type' => [ 'Shipping' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '0.00' } ], 'Type' => [ 'Tax' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '0.00' } ], 'Type' => [ 'ShippingTax' ] } ] } ], 'ProductTaxCode' => [ 'PTC_PRODUCT_TAXABLE_A' ], 'AmazonOrderItemCode' => [ '40393989474939' ], 'ItemFees' => [ { 'Fee' => [ { 'Amount' => [ { 'currency' => 'GBP', 'content' => '-5.09' } ], 'Type' => [ 'Commission' ] } ] } ], 'Quantity' => [ '1' ], 'Title' => [ 'Barcelona Home Shirt 2007/08 L 43"/109cm' ], 'SKU' => [ '237741-655/L' ] } ], 'AmazonSessionID' => [ '203-4034021-8454761' ], 'OrderPostedDate' => [ '2007-12-15T08:03:26-08:00' ], 'BillingData' => [ { 'BuyerPhoneNumber' => [ '07793533558' ], 'BuyerEmailAddress' => [ 'karenwwebber1@yahoo.co.uk' ], 'Address' => [ { 'PostalCode' => [ 'cr0 0hx' ], 'StateOrRegion' => [ 'surrey' ], 'PhoneNumber' => [ '07793533558' ], 'AddressFieldOne' => [ '97 godric cres' ], 'City' => [ 'croydon' ], 'Name' => [ 'karen webber' ], 'CountryCode' => [ 'GB' ] } ], 'BuyerName' => [ 'karen webber' ] } ] } ] }, { 'MessageID' => [ '2' ], 'OrderReport' => [ { 'FulfillmentData' => [ { 'FulfillmentMethod' => [ 'Ship' ], 'Address' => [ { 'PostalCode' => [ 'G31 3NN' ], 'StateOrRegion' => [ 'Lanarkshire' ], 'PhoneNumber' => [ '07923448560' ], 'AddressFieldOne' => [ 'Flat 1/2, 404 Cumbernauld Road' ], 'City' => [ 'Glasgow' ], 'Name' => [ 'Tegan Howard' ], 'CountryCode' => [ 'GB' ] } ], 'FulfillmentServiceLevel' => [ 'Expedited' ] } ], 'OrderDate' => [ '2007-12-15T06:26:08-08:00' ], 'AmazonOrderID' => [ '026-0242159-5849124' ], 'Item' => [ { 'ItemPrice' => [ { 'Component' => [ { 'Amount' => [ { 'currency' => 'GBP', 'content' => '39.99' } ], 'Type' => [ 'Principal' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '5.95' } ], 'Type' => [ 'Shipping' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '0.00' } ], 'Type' => [ 'Tax' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '0.00' } ], 'Type' => [ 'ShippingTax' ] } ] } ], 'ProductTaxCode' => [ 'PTC_PRODUCT_TAXABLE_A' ], 'AmazonOrderItemCode' => [ '17142556682403' ], 'ItemFees' => [ { 'Fee' => [ { 'Amount' => [ { 'currency' => 'GBP', 'content' => '-6.89' } ], 'Type' => [ 'Commission' ] } ] } ], 'Quantity' => [ '1' ], 'Title' => [ 'Manchester United Away Shirt 2007/08 XXL 48"/127cm' ], 'SKU' => [ '238347-010/XXL' ] } ], 'AmazonSessionID' => [ '026-0242159-5849124' ], 'OrderPostedDate' => [ '2007-12-15T06:26:08-08:00' ], 'BillingData' => [ { 'BuyerPhoneNumber' => [ '07923448560' ], 'BuyerEmailAddress' => [ 'tevalegan@yahoo.com' ], 'Address' => [ { 'PostalCode' => [ 'G31 3NN' ], 'StateOrRegion' => [ 'Lanarkshire' ], 'PhoneNumber' => [ '07923448560' ], 'AddressFieldOne' => [ 'Flat 1/2, 404 Cumbernauld Road' ], 'City' => [ 'Glasgow' ], 'Name' => [ 'Tegan Howard' ], 'CountryCode' => [ 'GB' ] } ], 'BuyerName' => [ 'Tegan Howard' ] } ] } ] }, { 'MessageID' => [ '3' ], 'OrderReport' => [ { 'FulfillmentData' => [ { 'FulfillmentMethod' => [ 'Ship' ], 'Address' => [ { 'PostalCode' => [ 'BS21 6US' ], 'StateOrRegion' => [ 'Somerset' ], 'PhoneNumber' => [ '01275875744' ], 'City' => [ 'Clevedon' ], 'AddressFieldOne' => [ 'Channel View Farm' ], 'AddressFieldTwo' => [ 'Kingston Seymour' ], 'Name' => [ 'Mrs. K. E. Stuckey' ], 'CountryCode' => [ 'GB' ] } ], 'FulfillmentServiceLevel' => [ 'Expedited' ] } ], 'OrderDate' => [ '2007-12-15T08:08:53-08:00' ], 'AmazonOrderID' => [ '203-1302512-5552320' ], 'Item' => [ { 'ItemPrice' => [ { 'Component' => [ { 'Amount' => [ { 'currency' => 'GBP', 'content' => '49.99' } ], 'Type' => [ 'Principal' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '5.95' } ], 'Type' => [ 'Shipping' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '0.00' } ], 'Type' => [ 'Tax' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '0.00' } ], 'Type' => [ 'ShippingTax' ] } ] } ], 'ProductTaxCode' => [ 'PTC_PRODUCT_TAXABLE_A' ], 'AmazonOrderItemCode' => [ '33456627889267' ], 'ItemFees' => [ { 'Fee' => [ { 'Amount' => [ { 'currency' => 'GBP', 'content' => '-8.39' } ], 'Type' => [ 'Commission' ] } ] } ], 'Quantity' => [ '1' ], 'Title' => [ 'England Supporters Home Rugby Shirt 2007/09 XXL 48"/127cm' ], 'SKU' => [ '234517-100/XXL' ] } ], 'AmazonSessionID' => [ '203-1302512-5552320' ], 'OrderPostedDate' => [ '2007-12-15T08:08:53-08:00' ], 'BillingData' => [ { 'BuyerPhoneNumber' => [ '07971 780408' ], 'BuyerEmailAddress' => [ 'stuckey@onetel.com' ], 'Address' => [ { 'PostalCode' => [ 'bs21 6us' ], 'StateOrRegion' => [ 'somerset' ], 'PhoneNumber' => [ '07971 780408' ], 'City' => [ 'kingston seymour' ], 'AddressFieldOne' => [ 'channel view farm' ], 'AddressFieldTwo' => [ 'middle lane' ], 'Name' => [ 'Mrs. K. Stuckey' ], 'CountryCode' => [ 'GB' ] } ], 'BuyerName' => [ 'Mrs. K. Stuckey' ] } ] } ] }, { 'MessageID' => [ '4' ], 'OrderReport' => [ { 'FulfillmentData' => [ { 'FulfillmentMethod' => [ 'Ship' ], 'Address' => [ { 'PostalCode' => [ 'ME17 1QW' ], 'StateOrRegion' => [ 'Kent' ], 'PhoneNumber' => [ '01622 858545' ], 'City' => [ 'Harrietsham' ], 'AddressFieldOne' => [ 'CET Safehouse' ], 'AddressFieldTwo' => [ 'Northdown House' ], 'Name' => [ 'Samantha Horton' ], 'CountryCode' => [ 'GB' ] } ], 'FulfillmentServiceLevel' => [ 'Standard' ] } ], 'OrderDate' => [ '2007-12-15T08:14:11-08:00' ], 'AmazonOrderID' => [ '202-2060132-2253123' ], 'Item' => [ { 'ItemPrice' => [ { 'Component' => [ { 'Amount' => [ { 'currency' => 'GBP', 'content' => '19.99' } ], 'Type' => [ 'Principal' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '2.63' } ], 'Type' => [ 'Shipping' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '0.00' } ], 'Type' => [ 'Tax' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '0.00' } ], 'Type' => [ 'ShippingTax' ] } ] } ], 'ProductTaxCode' => [ 'PTC_PRODUCT_TAXABLE_A' ], 'AmazonOrderItemCode' => [ '13193953510651' ], 'ItemFees' => [ { 'Fee' => [ { 'Amount' => [ { 'currency' => 'GBP', 'content' => '-3.39' } ], 'Type' => [ 'Commission' ] } ] } ], 'Quantity' => [ '1' ], 'Title' => [ 'Manchester United Woven Shorts with Brief Black M 32/34" waist' ], 'SKU' => [ '242677-010/32-34' ] }, { 'ItemPrice' => [ { 'Component' => [ { 'Amount' => [ { 'currency' => 'GBP', 'content' => '9.99' } ], 'Type' => [ 'Principal' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '1.32' } ], 'Type' => [ 'Shipping' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '0.00' } ], 'Type' => [ 'Tax' ] }, { 'Amount' => [ { 'currency' => 'GBP', 'content' => '0.00' } ], 'Type' => [ 'ShippingTax' ] } ] } ], 'ProductTaxCode' => [ 'PTC_PRODUCT_TAXABLE_A' ], 'AmazonOrderItemCode' => [ '47666133453459' ], 'ItemFees' => [ { 'Fee' => [ { 'Amount' => [ { 'currency' => 'GBP', 'content' => '-1.70' } ], 'Type' => [ 'Commission' ] } ] } ], 'Quantity' => [ '1' ], 'Title' => [ 'Manchester United Home/Away Socks 2007/08 L 7.5-12 UK Foot' ], 'SKU' => [ '237955-010/L7/12' ] } ], 'AmazonSessionID' => [ '202-2060132-2253123' ], 'OrderPostedDate' => [ '2007-12-15T08:14:11-08:00' ], 'BillingData' => [ { 'BuyerPhoneNumber' => [ '01634 272422' ], 'BuyerEmailAddress' => [ 'shorton150884@hotmail.co.uk' ], 'Address' => [ { 'PostalCode' => [ 'ME3 0BB' ], 'StateOrRegion' => [ 'Kent' ], 'PhoneNumber' => [ '01634 272422' ], 'City' => [ 'Rochester' ], 'AddressFieldOne' => [ '14 West Lane' ], 'AddressFieldTwo' => [ 'Isle Of Grain' ], 'Name' => [ 'Samantha Horton' ], 'CountryCode' => [ 'GB' ] } ], 'BuyerName' => [ 'Samantha Horton' ] } ] } ] } ], 'MessageType' => [ 'OrderReport' ], 'Header' => [ { 'MerchantIdentifier' => [ 'M_KITBAG_214004' ], 'DocumentVersion' => [ '1.01' ] } ], 'xsi:noNamespaceSchemaLocation' => 'amzn-envelope.xsd' };

What print line would print the AmazonOrderID value for the first customer?

Thanks for any help, I'm getting confused with what's a hash and what's an array and it's hurting my head [ponder]
 
Sorry

Code:
print $doc->{Message}{$key}->{'MessageID'}[0]->{AmazonOrderID}[0];

should of been

Code:
print $ref->{Message}{$key}->{'MessageID'}[0]->{AmazonOrderID}[0];

Also found the answer in case it's of use to any one else

Code:
print $ref->{Message}[$key]->{OrderReport}[$key]->{AmazonOrderID}[$key];
 
Ok, got another problem.

I'm now trying to find the length of the array AmazonOrderID

I've got this
Code:
$numberofcustomers = $ref->{Message}[$customer]->{OrderReport}[$customer]->{AmazonOrderID};

But it's giving me
Code:
ARRAY(0x96ebb18)

I think I might need a @ sign somewhere but not sure where

Can anyone help?

Thanks
 
try:

Code:
$numberofcustomers = [red]@[/red]$ref->{Message}[$customer]->{OrderReport}[$customer]->{AmazonOrderID};

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I tried that but got

Software error:
Not an ARRAY reference at new.cgi line 59.

 
instead of this:

print Dumper($ref);

do this:

print Dumper(\$ref);

and see if the print out is easier to read and thus understand the underlying data structe better.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks but it didn't come out any better :(

Also tried these

Code:
$bar = eval(Dumper($boo));
    print($@) if $@;
    print Dumper($boo), Dumper($bar);  # pretty print (no array indices)

    $Data::Dumper::Terse = 1;          # don't output names where feasible
    $Data::Dumper::Indent = 0;         # turn off all pretty print
    print Dumper($boo), "\n";

    $Data::Dumper::Indent = 1;         # mild pretty print
    print Dumper($boo);

    $Data::Dumper::Indent = 3;         # pretty print with array indices
    print Dumper($boo);

    $Data::Dumper::Useqq = 1;          # print strings in double quotes
    print Dumper($boo);
 
Ok, I've finished my script now so thank you for helping me.

This is what I got in the end incase it is ever of help to anyone wanting to pick up Amazon xml orders.

Code:
#!/usr/bin/perl -w



# include package

use CGI::Carp qw( fatalsToBrowser );

use CGI':standard';

use XML::Simple;

use Data::Dumper;


print "Content-type: text/html\n\n";



$FILENAME = "orders.xml";


my $ref = XMLin($FILENAME, ForceArray => 1);

open(FILE, "<$FILENAME");
flock(FILE, 2);
@file = <FILE>;
flock(FILE, 8);
close(FILE);

$customer=0;
foreach $line (@file) {
if ($line =~ m/<Message>/) {
$customer++;
$item=0;
}
if ($line =~ m/<Item>/) {;
$item++;
#print "Pushing $item <br>";
@items[$customer] = $item;
}

}

#print Dumper($ref);


$customerkey = 0;
for ($i = $customer; $i > 0; --$i) {

print "Amazon Order ID: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{AmazonOrderID}[0];
print "<br>";

print "Order Date: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{OrderDate}[0];
print "<br>";

print "Buyer's Email Address: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{BillingData}[0]->{BuyerEmailAddress}[0];
print "<br>";

print "Buyer's Name: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{BillingData}[0]->{BuyerName}[0];
print "<br>";

print "Buyer's Phone Number: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{BillingData}[0]->{BuyerPhoneNumber}[0];
print "<br>";

print "Buyer's Address:<br>";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{BillingData}[0]->{Address}[0]->{AddressFieldOne}[0];
print "<br>";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{BillingData}[0]->{Address}[0]->{City}[0];
print "<br>";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{BillingData}[0]->{Address}[0]->{StateOrRegion}[0];
print "<br>";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{BillingData}[0]->{Address}[0]->{PostalCode}[0];
print "<br>";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{BillingData}[0]->{Address}[0]->{CountryCode}[0];
print "<br><br>";

print "Shipping Phone Number: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{FulfillmentData}[0]->{Address}[0]->{PhoneNumber}[0];
print "<br>";
print "Shipping Address:<br>";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{FulfillmentData}[0]->{Address}[0]->{Name}[0];
print "<br>";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{FulfillmentData}[0]->{Address}[0]->{AddressFieldOne}[0];
print "<br>";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{FulfillmentData}[0]->{Address}[0]->{City}[0];
print "<br>";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{FulfillmentData}[0]->{Address}[0]->{StateOrRegion}[0];
print "<br>";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{FulfillmentData}[0]->{Address}[0]->{PostalCode}[0];
print "<br>";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{FulfillmentData}[0]->{Address}[0]->{CountryCode}[0];
print "<br><br>";
print "ITEMS:<br><br>";




$itemstart = ($items[$customerkey]) + 1;

$itemarray = 0;

for ($a = $itemstart; $a > 0; --$a) {

print "Amazon Order Item Code: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{Item}[$itemarray]->{AmazonOrderItemCode}[0];
print "<br>";
print "SKU: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{Item}[$itemarray]->{SKU}[0];
print "<br>";
print "Title: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{Item}[$itemarray]->{Title}[0];
print "<br>";
print "Qty: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{Item}[$itemarray]->{Quantity}[0];
print "<br>";
print "Price: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{Item}[$itemarray]->{ItemPrice}[0]->{Component}[0]->{Amount}[0]->{content};
print "<br>";
print "Shipping: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{Item}[$itemarray]->{ItemPrice}[0]->{Component}[1]->{Amount}[0]->{content};
print "<br>";
print "Tax: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{Item}[$itemarray]->{ItemPrice}[0]->{Component}[2]->{Amount}[0]->{content};
print "<br>";
print "ShippingTax: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{Item}[$itemarray]->{ItemPrice}[0]->{Component}[3]->{Amount}[0]->{content};
print "<br>";
print "Commission: ";
print $ref->{Message}[$customerkey]->{OrderReport}[0]->{Item}[$itemarray]->{ItemFees}[0]->{Fee}[0]->{Amount}[0]->{content};
print "<br><br>";

$itemarray++;
}

$customerkey++;
print "<br><br><br><br>";
}

print "<br>Done";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top