in reply to Re: Compare complex perl data structures
in thread Compare complex perl data structures

Thanks so much for replying BrowserUk.But, the issue is Dump is not working when both the data structures are not in order. For e.g. Though these two data structures are the same, since they are not sorted,output says that they are different.
my @array1 = [ {'platformid' => '100','da' => 'A.9','os' => 'microsoft amd64 wNT-6.1- +S','ma' => 'A.9','cc' => 'A.9','size' => [{'objecttype' => 'OB2BAR',' +totalsize' => '230986 KB','application' => 'IDB','hostname' => '5096' +},{'objecttype' => 'WINFS','totalsize' => '1262152 KB','application' +=> 'R: [New Volume]','hostname' => '5096'},{'objecttype' => 'WINFS',' +totalsize' => '574463 KB','application' => 'C:','hostname' => '5096'} +],'objecttype' => '6','host' => '5096'}, {'platformid' => '22','da' => 'A.9','os' => 'hp-ux-11.31','host' => '2 +060','cc' => 'A.9','ma' => 'A.9','size' => [{'objecttype' => 'FILESYS +TEM','totalsize' => '3628129 KB','application' => '/depot','hostname' + => '2060'}],'objecttype' => '2'} ]; my @array2 = [ {'platformid' => '22','da' => 'A.9','os' => 'hp-ux-11.31','host' => '2 +060','cc' => 'A.9','ma' => 'A.9','size' => [{'objecttype' => 'FILESYS +TEM','totalsize' => '3628129 KB','application' => '/depot','hostname' + => '2060'}],'objecttype' => '2'}, {'platformid' => '100','da' => 'A.9','os' => 'microsoft amd64 wNT-6.1- +S','ma' => 'A.9','cc' => 'A.9','size' => [{'objecttype' => 'OB2BAR',' +totalsize' => '230986 KB','application' => 'IDB','hostname' => '5096' +},{'objecttype' => 'WINFS','totalsize' => '1262152 KB','application' +=> 'R: [New Volume]','hostname' => '5096'},{'objecttype' => 'WINFS',' +totalsize' => '574463 KB','application' => 'C:','hostname' => '5096'} +],'objecttype' => '6','host' => '5096'} ];

Replies are listed 'Best First'.
Re^3: Compare complex perl data structures
by Laurent_R (Canon) on Oct 16, 2016 at 21:50 UTC
    As they are, the data structures are not the same, because arrays are ordered collections of items, so that they are different even if they contain the same items, because the item order is different. But if order of the elements is not important to you, why don't you simply sort them before comparing them? Assuming the value of platformid is unique, it'd be quite easy to sort your arrayrefs on that.

    Please also note what johngg told you: your @array1 and @array2 have only one element each: a reference to an array containing two elements (which are themselves hashrefs). I am not sure that's really what you want.