in reply to How to write complete hash into CSV?
An important point is that $hash{offers}{offer} is an array of anon hashes (references to hash). I show how to print the keys of those hashes.
Past the "how to access this data" question, the idea of a CSV file brings up a raft of other issues. It would be helpful if you back up a bit and explain what your overall objective is? The data that you have doesn't normally fit well with a CSV representation. I for one am wondering what you intend to do with that CSV? There are other possibilities including SQLite that may be more suited to what your objective is?
#!usr/bin/perl use warnings; use strict; use Data::Dumper; my $VAR1 = { 'offers' => { 'offer' => [ { 'originalPrice' => {}, 'categoryId' => '25000800', 'sku' => 'PBSRW21', 'shipAmount' => { 'integral' => + '100000100', 'value' => '$ +1000001.00' }, 'merchantProductId' => '0081383 +91', 'revType' => '2', 'url' => { 'value' => 'http://r +d.bizrate.com/rd?t=https%3A%2F%2Fwww.acitydiscount.com%2FJohn-Boos-21 +-Wall-Mounted-Solid-Sorting-Shelf-18-Gauge-Stainless-PB-SRW-21.0.1383 +91.1.1.htm%3Futm_source%3Dbizrate%26utm_medium%3Dcse%26utm_campaign%3 +Dcse_biz%26ppcid%3D8%26link%3D13170103&mid=91353&cat_id=25000800&atom +=10704&prod_id=&oid=4608507152&pos=1&b_id=18&bid_type=0&bamt=a5fedf14 +fd8fec0d&cobrand=1&ppr=85e317571cc20ee0&rf=af1&af_assettype_id=12&af_ +creative_id=2932&af_id=[PUBLISHER_ID]&af_placement_id=1&dv=5786a95dec +b116ac2d79e70c5ddae351' }, 'id' => '4608507152', 'atomId' => '10704', 'images' => { 'image' => [ { 'y +size' => '400', 'x +size' => '400', 'v +alue' => 'http://d1-pub.bizrate.com/resize?sq=400&uid=4608507152' } ] }, 'rawUrl' => 'https://www.acityd +iscount.com/John-Boos-21-Wall-Mounted-Solid-Sorting-Shelf-18-Gauge-St +ainless-PB-SRW-21.0.138391.1.1.htm?utm_source=bizrate&utm_medium=cse& +utm_campaign=cse_biz&ppcid=8&link=13170103', 'shipType' => 'UNKNOWN', 'stock' => 'IN', 'description' => 'John Boos - P +B-SRW-21 Weight 5 lbs. Width 21 in. Depth 18 in. Height 16 in. Rating +s: NSF. John Boos 21 Wall Mounted Solid Sorting Shelf 18 Gauge Stainl +ess - in Shelving, Wall at ACityDiscount', 'merchantId' => '91353', 'brandId' => '271910', 'manufacturer' => 'John Boos', 'type' => 'OFFER', 'title' => 'John Boos 21 Wall M +ounted Solid Sorting Shelf 18 Gauge Stainless - PB-SRW-21', 'price' => { 'integral' => '956 +3', 'value' => '$95.63 +' } }, { 'originalPrice' => {}, 'categoryId' => '25000800', 'sku' => 'DT6R23X', 'shipAmount' => { 'integral' => + '100000100', 'value' => '$ +1000001.00' }, 'merchantProductId' => '0080147 +82', 'revType' => '2', 'url' => { 'value' => 'http://r +d.bizrate.com/rd?t=https%3A%2F%2Fwww.acitydiscount.com%2FAdvance-Tabc +o-62-Wall-Mounted-Tubular-Sorting-Shelf-Stainless-Knock-Down-DT-6R-23 +-X.0.14782.1.1.htm%3Futm_source%3Dbizrate%26utm_medium%3Dcse%26utm_ca +mpaign%3Dcse_biz%26ppcid%3D8%26link%3D13170103&mid=91353&cat_id=25000 +800&atom=10704&prod_id=&oid=5266795020&pos=1&b_id=18&bid_type=0&bamt= +a5fedf14fd8fec0d&cobrand=1&ppr=d3a45a91cc13e426&rf=af1&af_assettype_i +d=12&af_creative_id=2932&af_id=[PUBLISHER_ID]&af_placement_id=1&dv=57 +86a95decb116ac2d79e70c5ddae351' }, 'id' => '5266795020', 'atomId' => '10704', 'images' => { 'image' => [ { 'y +size' => '400', 'x +size' => '400', 'v +alue' => 'http://d1-pub.bizrate.com/resize?sq=400&uid=5266795020' } ] }, 'rawUrl' => 'https://www.acityd +iscount.com/Advance-Tabco-62-Wall-Mounted-Tubular-Sorting-Shelf-Stain +less-Knock-Down-DT-6R-23-X.0.14782.1.1.htm?utm_source=bizrate&utm_med +ium=cse&utm_campaign=cse_biz&ppcid=8&link=13170103', 'shipType' => 'UNKNOWN', 'stock' => 'IN', 'description' => 'Advance Tabco + - DT-6R-23-X,DT-6R-23 Weight 30 lbs. Width 18 in. Depth 62 in. Heigh +t 11.25 in. Ratings: NSF. Advance Tabco 62 Wall Mounted Tubular Sorti +ng Shelf Stainless Knock Down - in Shelving, Wall at ACityDiscount', 'merchantId' => '91353', 'brandId' => '41378', 'manufacturer' => 'Advance Tabc +o', 'type' => 'OFFER', 'title' => 'Advance Tabco 62 Wa +ll Mounted Tubular Sorting Shelf Stainless Knock Down - DT-6R-23-X', 'price' => { 'integral' => '380 +19', 'value' => '$380.1 +9' } } ] } }; my %hash = %$VAR1; # reconstruct the hash table #print Dumper \%hash; # produces your data as posted foreach my $key (keys %hash) { print "first level key = $key\n"; # prints first level key = offers } foreach my $subkey (keys %{$hash{offers}}) { print "subkey = $subkey\n"; #prints subkey = offer } foreach my $hashref (@{$hash{offers}{offer}}) { print "\nhashref = $hashref\n"; # prints: # hashref = HASH(0xa193ac) # hashref = HASH(0xa197fc) foreach my $subsub_hashKey (sort keys %$hashref) { print "subsub_hashKey = $subsub_hashKey\n"; } } __END__ first level key = offers subkey = offer hashref = HASH(0xa8a4cc) subsub_hashKey = atomId subsub_hashKey = brandId subsub_hashKey = categoryId subsub_hashKey = description subsub_hashKey = id subsub_hashKey = images subsub_hashKey = manufacturer subsub_hashKey = merchantId subsub_hashKey = merchantProductId subsub_hashKey = originalPrice subsub_hashKey = price subsub_hashKey = rawUrl subsub_hashKey = revType subsub_hashKey = shipAmount subsub_hashKey = shipType subsub_hashKey = sku subsub_hashKey = stock subsub_hashKey = title subsub_hashKey = type subsub_hashKey = url hashref = HASH(0xa18fbc) subsub_hashKey = atomId subsub_hashKey = brandId subsub_hashKey = categoryId subsub_hashKey = description subsub_hashKey = id subsub_hashKey = images subsub_hashKey = manufacturer subsub_hashKey = merchantId subsub_hashKey = merchantProductId subsub_hashKey = originalPrice subsub_hashKey = price subsub_hashKey = rawUrl subsub_hashKey = revType subsub_hashKey = shipAmount subsub_hashKey = shipType subsub_hashKey = sku subsub_hashKey = stock subsub_hashKey = title subsub_hashKey = type subsub_hashKey = url Process completed successfully
|
|---|