title: extracting various structured data from hashref
body: <p>I have a hash, into which error messages are collected.
  In the hash,  <code>__errlist__</code> is a key and then there is list of one value, which can be string, hash or nested hash like can be seen below:</p>
  <p>String:</p>
  <pre><code>{'_errlist_' =&gt; ['Empty table error - data load failed.']}
          
  </code></pre>
  <p>Hash:</p>
  <pre><code> { '_errlist_' =&gt; [
       {'message' =&gt; 'Prepare failed: [Teradata][ODBC Teradata Driver][Teradata Database](-5628)Column DWH_TENANT_ID not found in Q. (SQL-HY000) '}]}
  </code></pre>
  <p>Nested hash:</p>
  <pre><code>{'_errlist_' =&gt; [
       {'message' =&gt; 
           {'message' =&gt; 'Prepare failed: [Teradata][ODBC Teradata Driver][Teradata Database](-5628)Column not found . (SQL-HY000) '}}]}
  </code></pre>
  <p>or:</p>
  <pre><code>{'_errlist_' =&gt; [
      {'message' =&gt; 
           {'message' =&gt; 
               {'message' =&gt; 'Prepare failed: [Teradata][ODBC Teradata Driver][Teradata Database](-5628)Column not found . (SQL-HY000) '
                          }}}]}
  
  
   
  </code></pre>
  <p>What I came up with is:</p>
  <pre><code> if (defined($RunActSeq-&gt;[0]-&gt;{'_errlist_'}-&gt;[0]-&gt;{'message'}-&gt;{'message'}-&gt;{'message'})){
    $errmsg = $RunActSeq-&gt;[0]-&gt;{'_errlist_'}-&gt;[0]-&gt;{'message'}-&gt;{'message'}-&gt;{'message'};
  } elsif (defined($RunActSeq-&gt;[0]-&gt;{'_errlist_'}-&gt;[0])){
    $errmsg = $RunActSeq-&gt;[0]-&gt;{'_errlist_'}-&gt;[0];
  } elsif (defined($RunActSeq-&gt;[0]-&gt;{'_errlist_'}-&gt;[0]-&gt;{'message'}-&gt;{'message'})){
    $errmsg = $RunActSeq-&gt;[0]-&gt;{'_errlist_'}-&gt;[0]-&gt;{'message'}-&gt;{'message'};
  } elsif (defined($RunActSeq-&gt;[0]-&gt;{'_errlist_'}-&gt;[0]-&gt;{'message'})  ){
    $errmsg = $RunActSeq-&gt;[0]-&gt;{'_errlist_'}-&gt;[0]-&gt;{'message'};
  } else {
    $errmsg = &quot;Undefined Error&quot;;
  }
  </code></pre>
  <p>But I'm still not getting the messages when extracting error messages strings, most of the time I get <code>HASH(0x3c04250)</code> not the message text.</p>
  <p>Does anybody pls know how to extract error message more accurately?</p>