I can access my Data Structure

I have this data structure:

%MEN =(
     pub => {
      level => '3',
      sub => ["Apostilas", "Papers","Libros"],
      subsub =>["1998","1999","2000"],
    },
   );

And this other:
%pubi = (
      level => '3',
      sub => ["Apostilas", "Papers","Libros"],
      subsub =>["1998","1999","2000"],
    );

I need :
1)To print all the elements of array subsub[]
2)Add news leemnts to this array

My problem is:
That I cannot to access this array.
I have tried this:

    foreach $var (keys %MEN){
      if ($var eq $menu) {
          for $rol (keys %{ $MEN{$var} }) {
            if ($rol eq "sub"){
                print "$rol = $MEN{$var}{$rol}[2]"; #this work, print the 3dr element, but I need all the elements
                                          #without knowing the number of elements
                    for ($i=0;$i<5;$i++){           #thniking that there is no more of 5 elements :)
                  print $MEN->{$var}{$rol}[$i]; # Dont work :((
                  }
            }
          }
      }
    }

The same with the other structure:
for ($i=0;$i<=5;$i++){
    print $pubi->{sub}[$i]; #DONT work....
}

How can I to acces this elements of the array?
How can I to add an new element?

Thanks in advanced!!!
hakimusAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Kim RyanConnect With a Mentor IT ConsultantCommented:
# get anonymous array reference
$array_ref = \@{ $MEN{pub}{subsub} };
print(@$array_ref,"\n");
# push to dereferenced array
push(@$array_ref, '2001');
# value added!
print($MEN{pub}{subsub}[3]);
0
 
Kim RyanIT ConsultantCommented:
# get anonymous array reference
$array_ref = \@{ $MEN{pub}{subsub} };
print(@$array_ref,"\n");
# push to dereferenced array
push(@$array_ref, '2001');
# value added!
print($MEN{pub}{subsub}[3]);
0
 
hakimusAuthor Commented:
This is working good....by now :)
Thanks!!
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Kim RyanIT ConsultantCommented:
If this does want you want, you may like to accept this comment as the answer so the question can be closed off(and I can get some points :)
0
 
ozoCommented:
push @{$MEN{pub}{subsub}},2001;
print "@{$MEN{pub}{subsub}}\n";
0
 
hakimusAuthor Commented:
well, I still am doing some tests :)
Anything i will return with more questions (and points for the answers)
0
All Courses

From novice to tech pro — start learning today.