I have a perl script which evaluates an xml script using the keys() function. My script is written in such a way, attributes/tags in xml are not coming in order. Does the keys function in perl, evaluate randomly??
Ex:
if( (keys %{$data})[0] eq 'fileFooter' and
(keys %{$data->{fileFooter}})[0] eq 'measCollec' and
(keys %{$data->{fileFooter}->{measCollec}})[0] eq 'endTime' and
(keys %{$data})[1] eq 'fileHeader' and
(keys %{$data->{fileHeader}})[0] eq 'measCollec' and
(keys %{$data->{fileHeader}->{measCollec}})[0] eq 'beginTime'
Here the fileFooter attribute in XML file is coming at the end and the fileHEader is coming at the beginning. In this case perl will work fine??
Please find the script in below link : https://docs.zoho.com/writer/published.do?rid=x6jdb8effa7ba9b0140258c9b3b1fb9617386
Please find the XML file in below link :
https://docs.zoho.com/writer/ropen.do?rid=x6jdbcd99dd2df097455f99fa2907a84620ee
Hashes do not store keys in a reliable order. This is the nature of hashes, either use the sort function or use an array. See: http://perldoc.perl.org/functions/keys.html