in reply to how to access array of hash with arrays?

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!

Replies are listed 'Best First'.
Re^2: how to access array of hash with arrays?
by buchi2 (Acolyte) on Jul 25, 2017 at 15:27 UTC
    P.S.:

    Is it not necessary to give an & in front, if I call a subroutine?