Hello buchi2,

Welcome to the monastery.

It works almost as you have it, see sample of code bellow:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; sub dofn { my %hashfn; my ($ivon, $ibis, $imal) = @_; for (my $i = $ivon; $i < $ibis; $i++) { push(@{$hashfn{'var1'}}, $i*$imal); push(@{$hashfn{'var2'}}, $i*$imal*10.); push(@{$hashfn{'var3'}}, $i*$imal*20.); } return \%hashfn; } my $hierhash_1 = dofn(0, 5, 1); # print "1 $hierhash_1->{'var2'}[3] \n"; push(my @hashfeld, $hierhash_1); my $hierhash_2 = dofn(0, 5, 2); # print "2 $hierhash_2->{'var2'}[3] \n"; push(@hashfeld, $hierhash_2); # print Dumper \@hashfeld; my $wert = $hashfeld[0]->{'var2'}[3]; print "$wert \n"; __END__ $ perl test.pl 30

Update: I modified a bit your code. I would suggest a few points to read and it is up to you how you will proceed. I would suggest not to use subroutines/Prototypes use simply subroutines/Pass by Reference. Why? A fellow monk haukex wrote a recent post about it Fun with Prototypes.

On Perl you do not need to pre-define your parameters you can use my straight on the parameter when you assign the value.

Last point to mention, I would return a reference (hashref, arrayref, complexref) instead of the hash. Why? Read more here Subroutines: Returning a hash vs. hash reference.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: how to access array of hash with arrays? by thanos1983
in thread how to access array of hash with arrays? by buchi2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.