Hi PM,
I've a xml file & have read into hashes; actually xml is quite complex. Below is the example of single product. I've used XML::Simple to create hash.
I want to extract few values & print it to a csv file. There are many <product> under <products> tag.
To extract 'image_link', I tried this but it prints image_url many time (no of keys). I just want it once.
foreach my $d (keys %{$doc->{'results'}{'result'}{'output'}{'products'
+}{'product'}}) {
print $doc->{'results'}{'result'}{'output'}{'products'}{'produ
+ct'}{'image_link'} . "\n";
}
$VAR1 = {
'xmlns' => 'http://marketlive.com/integration/xmlbean',
'results' => {
'info' => {
'environment' => 'prdv596',
'vmId' => 'iws-currentusa-prdv596-int
+0001',
'site' => 'currentusa',
'systemLocale' => 'en_US',
'vmType' => 'production-iws',
'timeStamp' => 'Mon Aug 17 02:35:02 P
+DT 2015',
'host' => 'localhost'
},
'result' => {
'summary' => {
'xmlns' => 'http://mar
+ketlive.com/integration/xmlbean',
'failed' => '0',
'total' => '15248'
},
'output' => {
'products' => {
'xmlns' =
+> 'http://marketlive.com/integration/xmlbean',
'product'
+ => {
+ 'xmlns' => 'http://marketlive.com/integration/xmlbean',
+ 'suppressSwatches' => 'true',
+ 'dateModified' => '2013-06-05T08:12:59.368-07:00',
+ 'imagePages' => {
+ 'imagePage' => {
+ 'siteImages' => {
+ 'siteImage' => {
+ 'de
+tail' => '/lillianvernon/products/42642_dt.jpg',
+ 'al
+ternateLarge1' => '/lillianvernon/products/viewlarger/42642_lg.jpg',
+ 'si
+teCode' => 'lillianvernon',
+ 'th
+umb' => '/lillianvernon/products/42642_th.jpg'
+ }
+ },
+ 'locale' => 'en_US'
+ }
+ },
+ 'dateActivate' => '2013-06-05T08:12:00.000-07:00',
+ 'imageTargetPages' => {
+ 'imageTargetPage' => {
+ 'siteImageTargets' =>
+{
+
+'siteImageTarget' => [
+
+ {
+
+ 'zoom1Image' => '/lillianvernon/products/42642
+_dt.jpg',
+
+ 'siteCode' => 'lillianvernon'
+
+ },
+
+ {
+
+ 'zoom1Image' => '/lillianvernon/products/42642
+_dt.jpg',
+
+ 'siteCode' => 'currentcatalog'
+
+ },
+
+ {
+
+ 'zoom1Image' => '/lillianvernon/products/42642
+_dt.jpg',
+
+ 'siteCode' => 'currentlabels'
+
+ },
+
+ {
+
+ 'zoom1Image' => '/lillianvernon/products/42642
+_dt.jpg',
+
+ 'siteCode' => 'colorfulimages'
+
+ }
+
+ ]
+ },
+ 'locale' => 'en_US'
+ }
+ },
+ 'skus' => {
+ 'sku' => [
+ {
+ 'attributePages' => {
+ 'attributePage' => {
+ 'name
+' => 'assignedAttributePage',
+ 'attr
+ibutes' => {
+
+ 'value' => 'Small',
+
+ 'name' => 'Size Family'
+
+ }
+ }
+ },
+ 'productSkuLinks' => {
+ 'productSkuLink' => {
+ 'pr
+oductCode' => '42642',
+ 'de
+faultProduct' => 'false'
+ }
+ },
+ 'dateModified' => '2015-05-11T06:41:50.000-0
+7:00',
+ 'skuTypeId' => '1',
+ 'dateActivate' => '2010-12-07T00:00:00.000-0
+8:00',
+ 'weight' => '0.0',
+ 'code' => '426426',
+ 'dateCreated' => '2010-12-07T14:22:24.724-08
+:00',
+ 'skuOptionLinks' => {
+ 'skuOptionLink' => {
+ 'opti
+onTypeCode' => 'SIZE',
+ 'opti
+onCode' => '6'
+ }
+ },
+ 'pk' => '100186',
+ 'active' => 'false',
+ 'taxable' => 'true',
+ 'deleted' => 'false',
+ 'giftWrap' => 'false',
+ 'shippingChargeable' => 'true',
+ 'dateDeactivate' => '2040-12-07T00:00:00.000
+-08:00',
+ 'inventories' => {
+ 'inventory' => {
+ 'pk' => '100
+186',
+ 'dateModifie
+d' => '2010-12-07T14:22:24.724-08:00',
+ 'inventorySe
+tCode' => 'lillianvernon',
+ 'deleted' =>
+ 'false',
+ 'minStock' =
+> '10',
+ 'stock' => '
+500',
+ 'ordinal' =>
+ '0',
+ 'dateRestock
+' => '2011-12-15T00:00:00.000-08:00',
+ 'code' => '4
+26426',
+ 'dateCreated
+' => '2010-12-07T14:22:24.724-08:00'
+ }
+ },
+ 'overWeight' => 'false',
+ 'prices' => {
+ 'price' => {
+ 'salePrice' => '158.0
+0',
+ 'currency' => 'USD',
+ 'regularPrice' => '15
+8.00',
+ 'overweightPrice' =>
+'0.00'
+ }
+ }
+ },
+ {
+ 'attributePages' => {
+ 'attributePage' => {
+ 'name
+' => 'assignedAttributePage',
+ 'attr
+ibutes' => {
+
+ 'value' => 'Medium',
+
+ 'name' => 'Size Family'
+
+ }
+ }
+ },
+ 'productSkuLinks' => {
+ 'productSkuLink' => {
+ 'pr
+oductCode' => '42642',
+ 'de
+faultProduct' => 'false'
+ }
+ },
+ 'dateModified' => '2015-05-11T06:41:50.000-0
+7:00',
+ 'skuTypeId' => '1',
+ 'dateActivate' => '2010-12-07T00:00:00.000-0
+8:00',
+ 'weight' => '0.0',
+ 'code' => '4264216',
+ 'dateCreated' => '2010-12-07T14:26:12.380-08
+:00',
+ 'skuOptionLinks' => {
+ 'skuOptionLink' => {
+ 'opti
+onTypeCode' => 'SIZE',
+ 'opti
+onCode' => '16'
+ }
+ },
+ 'pk' => '100191',
+ 'active' => 'false',
+ 'taxable' => 'true',
+ 'deleted' => 'false',
+ 'giftWrap' => 'false',
+ 'shippingChargeable' => 'true',
+ 'dateDeactivate' => '2040-12-07T00:00:00.000
+-08:00',
+ 'inventories' => {
+ 'inventory' => {
+ 'pk' => '100
+191',
+ 'dateModifie
+d' => '2010-12-07T14:26:12.599-08:00',
+ 'inventorySe
+tCode' => 'lillianvernon',
+ 'deleted' =>
+ 'false',
+ 'minStock' =
+> '10',
+ 'stock' => '
+500',
+ 'ordinal' =>
+ '0',
+ 'dateRestock
+' => '2011-12-15T00:00:00.000-08:00',
+ 'code' => '4
+264216',
+ 'dateCreated
+' => '2010-12-07T14:26:12.599-08:00'
+ }
+ },
+ 'overWeight' => 'false',
+ 'prices' => {
+ 'price' => {
+ 'salePrice' => '158.0
+0',
+ 'currency' => 'USD',
+ 'regularPrice' => '15
+8.00',
+ 'overweightPrice' =>
+'0.00'
+ }
+ }
+ },
+ {
+ 'attributePages' => {
+ 'attributePage' => {
+ 'name
+' => 'assignedAttributePage',
+ 'attr
+ibutes' => {
+
+ 'value' => 'Small',
+
+ 'name' => 'Size Family'
+
+ }
+ }
+ },
+ 'productSkuLinks' => {
+ 'productSkuLink' => {
+ 'pr
+oductCode' => '42642',
+ 'de
+faultProduct' => 'false'
+ }
+ },
+ 'dateModified' => '2015-05-11T06:41:50.000-0
+7:00',
+ 'skuTypeId' => '1',
+ 'dateActivate' => '2010-12-07T00:00:00.000-0
+8:00',
+ 'weight' => '0.0',
+ 'code' => '426422',
+ 'dateCreated' => '2010-12-07T14:15:45.021-08
+:00',
+ 'skuOptionLinks' => {
+ 'skuOptionLink' => {
+ 'opti
+onTypeCode' => 'SIZE',
+ 'opti
+onCode' => '2'
+ }
+ },
+ 'pk' => '100184',
+ 'active' => 'false',
+ 'taxable' => 'true',
+ 'deleted' => 'false',
+ 'giftWrap' => 'false',
+ 'shippingChargeable' => 'true',
+ 'dateDeactivate' => '2040-12-07T00:00:00.000
+-08:00',
+ 'inventories' => {
+ 'inventory' => {
+ 'pk' => '100
+184',
+ 'dateModifie
+d' => '2010-12-07T14:15:45.021-08:00',
+ 'inventorySe
+tCode' => 'lillianvernon',
+ 'deleted' =>
+ 'false',
+ 'minStock' =
+> '10',
+ 'stock' => '
+500',
+ 'ordinal' =>
+ '0',
+ 'dateRestock
+' => '2011-12-15T00:00:00.000-08:00',
+ 'code' => '4
+26422',
+ 'dateCreated
+' => '2010-12-07T14:15:45.021-08:00'
+ }
+ },
+ 'overWeight' => 'false',
+ 'prices' => {
+ 'price' => {
+ 'salePrice' => '158.0
+0',
+ 'currency' => 'USD',
+ 'regularPrice' => '15
+8.00',
+ 'overweightPrice' =>
+'0.00'
+ }
+ }
+ },
+ {
+ 'attributePages' => {
+ 'attributePage' => {
+ 'name
+' => 'assignedAttributePage',
+ 'attr
+ibutes' => {
+
+ 'value' => 'Small',
+
+ 'name' => 'Size Family'
+
+ }
+ }
+ },
+ 'productSkuLinks' => {
+ 'productSkuLink' => {
+ 'pr
+oductCode' => '42642',
+ 'de
+faultProduct' => 'false'
+ }
+ },
+ 'dateModified' => '2015-05-11T06:41:50.000-0
+7:00',
+ 'skuTypeId' => '1',
+ 'dateActivate' => '2010-12-07T00:00:00.000-0
+8:00',
+ 'weight' => '0.0',
+ 'code' => '4264210',
+ 'dateCreated' => '2010-12-07T14:23:44.755-08
+:00',
+ 'skuOptionLinks' => {
+ 'skuOptionLink' => {
+ 'opti
+onTypeCode' => 'SIZE',
+ 'opti
+onCode' => '10'
+ }
+ },
+ 'pk' => '100188',
+ 'active' => 'false',
+ 'taxable' => 'true',
+ 'deleted' => 'false',
+ 'giftWrap' => 'false',
+ 'shippingChargeable' => 'true',
+ 'dateDeactivate' => '2040-12-07T00:00:00.000
+-08:00',
+ 'inventories' => {
+ 'inventory' => {
+ 'pk' => '100
+188',
+ 'dateModifie
+d' => '2010-12-07T14:23:44.755-08:00',
+ 'inventorySe
+tCode' => 'lillianvernon',
+ 'deleted' =>
+ 'false',
+ 'minStock' =
+> '10',
+ 'stock' => '
+500',
+ 'ordinal' =>
+ '0',
+ 'dateRestock
+' => '2011-12-15T00:00:00.000-08:00',
+ 'code' => '4
+264210',
+ 'dateCreated
+' => '2010-12-07T14:23:44.755-08:00'
+ }
+ },
+ 'overWeight' => 'false',
+ 'prices' => {
+ 'price' => {
+ 'salePrice' => '158.0
+0',
+ 'currency' => 'USD',
+ 'regularPrice' => '15
+8.00',
+ 'overweightPrice' =>
+'0.00'
+ }
+ }
+ },
+ {
+ 'attributePages' => {
+ 'attributePage' => {
+ 'name
+' => 'assignedAttributePage',
+ 'attr
+ibutes' => {
+
+ 'value' => 'Small',
+
+ 'name' => 'Size Family'
+
+ }
+ }
+ },
+ 'productSkuLinks' => {
+ 'productSkuLink' => {
+ 'pr
+oductCode' => '42642',
+ 'de
+faultProduct' => 'false'
+ }
+ },
+ 'dateModified' => '2015-05-11T06:41:50.000-0
+7:00',
+ 'skuTypeId' => '1',
+ 'dateActivate' => '2010-12-07T00:00:00.000-0
+8:00',
+ 'weight' => '0.0',
+ 'code' => '426424',
+ 'dateCreated' => '2010-12-07T14:18:11.505-08
+:00',
+ 'skuOptionLinks' => {
+ 'skuOptionLink' => {
+ 'opti
+onTypeCode' => 'SIZE',
+ 'opti
+onCode' => '4'
+ }
+ },
+ 'pk' => '100185',
+ 'active' => 'false',
+ 'taxable' => 'true',
+ 'deleted' => 'false',
+ 'giftWrap' => 'false',
+ 'shippingChargeable' => 'true',
+ 'dateDeactivate' => '2040-12-07T00:00:00.000
+-08:00',
+ 'inventories' => {
+ 'inventory' => {
+ 'pk' => '100
+185',
+ 'dateModifie
+d' => '2010-12-07T14:18:11.505-08:00',
+ 'inventorySe
+tCode' => 'lillianvernon',
+ 'deleted' =>
+ 'false',
+ 'minStock' =
+> '10',
+ 'stock' => '
+500',
+ 'ordinal' =>
+ '0',
+ 'dateRestock
+' => '2011-12-15T00:00:00.000-08:00',
+ 'code' => '4
+26424',
+ 'dateCreated
+' => '2010-12-07T14:18:11.505-08:00'
+ }
+ },
+ 'overWeight' => 'false',
+ 'prices' => {
+ 'price' => {
+ 'salePrice' => '158.0
+0',
+ 'currency' => 'USD',
+ 'regularPrice' => '15
+8.00',
+ 'overweightPrice' =>
+'0.00'
+ }
+ }
+ },
+ {
+ 'attributePages' => {
+ 'attributePage' => {
+ 'name
+' => 'assignedAttributePage',
+ 'attr
+ibutes' => {
+
+ 'value' => 'Small',
+
+ 'name' => 'Size Family'
+
+ }
+ }
+ },
+ 'productSkuLinks' => {
+ 'productSkuLink' => {
+ 'pr
+oductCode' => '42642',
+ 'de
+faultProduct' => 'false'
+ }
+ },
+ 'dateModified' => '2015-05-11T06:41:50.000-0
+7:00',
+ 'skuTypeId' => '1',
+ 'dateActivate' => '2010-12-07T00:00:00.000-0
+8:00',
+ 'weight' => '0.0',
+ 'code' => '4264212',
+ 'dateCreated' => '2010-12-07T14:25:22.927-08
+:00',
+ 'skuOptionLinks' => {
+ 'skuOptionLink' => {
+ 'opti
+onTypeCode' => 'SIZE',
+ 'opti
+onCode' => '12'
+ }
+ },
+ 'pk' => '100189',
+ 'active' => 'false',
+ 'taxable' => 'true',
+ 'deleted' => 'false',
+ 'giftWrap' => 'false',
+ 'shippingChargeable' => 'true',
+ 'dateDeactivate' => '2040-12-07T00:00:00.000
+-08:00',
+ 'inventories' => {
+ 'inventory' => {
+ 'pk' => '100
+189',
+ 'dateModifie
+d' => '2010-12-07T14:25:22.927-08:00',
+ 'inventorySe
+tCode' => 'lillianvernon',
+ 'deleted' =>
+ 'false',
+ 'minStock' =
+> '10',
+ 'stock' => '
+500',
+ 'ordinal' =>
+ '0',
+ 'dateRestock
+' => '2011-12-15T00:00:00.000-08:00',
+ 'code' => '4
+264212',
+ 'dateCreated
+' => '2010-12-07T14:25:22.927-08:00'
+ }
+ },
+ 'overWeight' => 'false',
+ 'prices' => {
+ 'price' => {
+ 'salePrice' => '158.0
+0',
+ 'currency' => 'USD',
+ 'regularPrice' => '15
+8.00',
+ 'overweightPrice' =>
+'0.00'
+ }
+ }
+ },
+ {
+ 'attributePages' => {
+ 'attributePage' => {
+ 'name
+' => 'assignedAttributePage',
+ 'attr
+ibutes' => {
+
+ 'value' => 'Small',
+
+ 'name' => 'Size Family'
+
+ }
+ }
+ },
+ 'productSkuLinks' => {
+ 'productSkuLink' => {
+ 'pr
+oductCode' => '42642',
+ 'de
+faultProduct' => 'false'
+ }
+ },
+ 'dateModified' => '2015-05-11T06:41:50.000-0
+7:00',
+ 'skuTypeId' => '1',
+ 'dateActivate' => '2010-12-07T00:00:00.000-0
+8:00',
+ 'weight' => '0.0',
+ 'code' => '4264214',
+ 'dateCreated' => '2010-12-07T14:25:46.130-08
+:00',
+ 'skuOptionLinks' => {
+ 'skuOptionLink' => {
+ 'opti
+onTypeCode' => 'SIZE',
+ 'opti
+onCode' => '14'
+ }
+ },
+ 'pk' => '100190',
+ 'active' => 'false',
+ 'taxable' => 'true',
+ 'deleted' => 'false',
+ 'giftWrap' => 'false',
+ 'shippingChargeable' => 'true',
+ 'dateDeactivate' => '2040-12-07T00:00:00.000
+-08:00',
+ 'inventories' => {
+ 'inventory' => {
+ 'pk' => '100
+190',
+ 'dateModifie
+d' => '2010-12-07T14:25:46.130-08:00',
+ 'inventorySe
+tCode' => 'lillianvernon',
+ 'deleted' =>
+ 'false',
+ 'minStock' =
+> '10',
+ 'stock' => '
+500',
+ 'ordinal' =>
+ '0',
+ 'dateRestock
+' => '2011-12-15T00:00:00.000-08:00',
+ 'code' => '4
+264214',
+ 'dateCreated
+' => '2010-12-07T14:25:46.130-08:00'
+ }
+ },
+ 'overWeight' => 'false',
+ 'prices' => {
+ 'price' => {
+ 'salePrice' => '158.0
+0',
+ 'currency' => 'USD',
+ 'regularPrice' => '15
+8.00',
+ 'overweightPrice' =>
+'0.00'
+ }
+ }
+ },
+ {
+ 'attributePages' => {