Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I store a hash which is inside an array element?
    text
    copied!<h2>The background</h2> <p>I got a Perl module which utilizes an array for its input/output parameters, like this:</p> <pre><code>Execute({inputfile =&gt; $req-&gt;{modules}.'filename', param =&gt; \@xchange}); </code></pre> <p>Inside the module a hash is build and returned via reference</p> <pre><code>$param[0] = \%values; </code></pre> <p>This is all fine and good (I think) and <code>print Dumper @xchange[0];</code> will output my desired content as</p> <pre><code>$VAR1 = { '33' =&gt; 'Title1', '53' =&gt; 'Title2', '21' =&gt; 'Title3' }; </code></pre> <p><br></p> <h2>The goal</h2> <p>I would like to loop over the content and print the key/value pairs one by one, for example like this</p> <pre><code>%testhash = ('33' =&gt; 'Test1', '53' =&gt; 'Test2', '21' =&gt; 'Test3' ); foreach $key (keys %testhash) { print "LOOP: $key, value=$testhash{$key}\n"; } </code></pre> <p>This loop does work as intended and dumping my testhash via <code>print Dumper \%testhash;</code> outputs the same as the array element above</p> <pre><code>$VAR1 = { '33' =&gt; 'Test1', '53' =&gt; 'Test2', '21' =&gt; 'Test3' }; </code></pre> <p><br></p> <h2>The problem</h2> <p>The trouble now seems to be that although both structures appear to be of the same kind I cant get my head arround, how to properly access the returned hash which is stored inside @xchange[0].</p> <p>I did try <code>%realhash = @xchange[0];</code> and <code>%realhash = \@xchange[0];</code>, but then <code>print Dumper \%realhash;</code> will output <code>$VAR1 = { 'HASH(0xa7b29c0)' =&gt; undef };</code> or <code>$VAR1 = { 'REF(0xa7833a0)' =&gt; undef };</code> respectively.</p> <p>So I either need a way to get the content of @xchange[0] inside a clean new hash or a way to foreach loop over the hash inside the @xchange[0] element.</p> <p>I guess I am getting screwed by the whole hash reference concept, but I am at a loss here and can't think of another way to google for it. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload