Hello buchi2,

You are getting an array of arrays, I have altered the output so you can see it easier.

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

From there it is easy (I guess) on how to get the array or at least you can search online on how to extract an array from an array of arrays ;)

A few minor recommendations regarding your code (very briefly). You do not need to add the -w on the shebang, -w it is an alternative of using use warnings;. Also you do not need to use the & on your subroutines see here why What is the point of the & / ampersand sigil for function refs?.

Update: I used Data::Dumper to debug the output, I think you will find it extremely useful, at least I do. :)

Update2: Fellow monk hexcoder provided you already an answer to your question so I thought it would be nice also to add some minor notes on your code. In Perl you do not need to predefine your variables you can define them the moment you assign them. Also I found very useful the feature say. It is like print but it add an new line character \n at the end your string or what ever attribute you are calling.

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

Update3: One more reference to read from a similar question Dereference array of arrays.

Hope this helps, BR.

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

In reply to Re: How to get out an array of a hash? (Updated) by thanos1983
in thread How to get out an array of a hash? 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.