title: Perl, Parsing XML with XML::Simple and Having Issues
body: <p>I am parsing xml files in Perl and everything seems to work great with one issue. I have files with the same schema, but they are returning different types of data from the parser. Here is a simplified example:</p>
  
  <pre><code>&lt;tests&gt;
         &lt;test&gt;
            &lt;data1&gt;Hi&lt;/data1&gt;
            &lt;data2&gt;Hello&lt;/data2&gt;
         &lt;/test&gt;
         &lt;test&gt;
            &lt;data1&gt;Hi2&lt;/data1&gt;
            &lt;data2&gt;Hello2&lt;/data2&gt;
         &lt;/test&gt;
    &lt;/tests&gt;
  </code></pre>
  
  <p>In a dump, this returns the following: (Take note of test being an array of two hashes)</p>
  
  <pre><code>$VAR1 = {
            'test' =&gt; [
                      {
                        'data2' =&gt; 'Hello',
                        'data1' =&gt; 'Hi'
                      },
                      {
                        'data2' =&gt; 'Hello2',
                        'data1' =&gt; 'Hi2'
                      }
                    ]
          };
  </code></pre>
  
  <p>Now, for a similar set of data, but with only one 'test' entity like so:</p>
  
  <pre><code>  &lt;tests&gt;
         &lt;test&gt;
            &lt;data1&gt;Hi&lt;/data1&gt;
            &lt;data2&gt;Hello&lt;/data2&gt;
         &lt;/test&gt;
    &lt;/tests&gt;
  </code></pre>
  
  <p>This returns similar data, EXCEPT the test entity is no longer an array, but a singular hash:</p>
  
  <pre><code>$VAR1 = {
            'test' =&gt; {
                      'data2' =&gt; 'Hello',
                      'data1' =&gt; 'Hi'
                    }
          };
  </code></pre>
  
  <p>My dilemma is that my code expects an array there, as that is the norm. But on the slim chance when there is only one entity, it will return a hash for that entity. My question is, how can I handle the hash entity as though it were an array. Or test for it?</p>
  
  <p>Right now my code for retrieving the array is like this:</p>
  
  <pre><code>foreach $test (@{$data-&gt;{'tests'}-&gt;{'test'}})
  {
     do something with $test
  }
  </code></pre>
  
  <p>But with the hash, it gives an error "Not an ARRAY reference". I hope this is enough detail! Thanks!!!</p>