in reply to Print elements of hash references

Have a look at the perl data structures cookbook perldsc, it's a great intro to handling data.

40 global variables sounds like a lot, perhaps a hash would be more suitable & easier to manage ? ( but without seeing the code it's difficult to tell)

Replies are listed 'Best First'.
Re^2: Print elements of hash references
by Anonymous Monk on Mar 31, 2012 at 18:21 UTC

    Thanks for that I will have a look. Can you tell me how to do it with this particular example? Those are (I think) array references and not array of arays or hash or arrays etc that the perldsc have.

      Looks like you have a hash of hashes of arrays of arrays. The principle is the same no matter how far you nest.

      push @{$An{$n}->{b}} , $bb[$idx];

      let's see, if perldsc did not make it clear enough, maybe perldata and perllol will help a bit further?
      Anyway, looking for "references" and Hashes of Hashes (HoH) and Hashes of Arrays (HoA) in the documentation and also on this site may help you along.

      What you are doing is pushing onto an array reference that is inside a hash (%An) of hashes the value in position ($idx) of an array (@bb).

      I am a little curious though: If you don't know what you are doing, why are you doing it?

      To see the results, do try use Data::Dumper;print Dumper \%An;

      Cheers, Sören

      where did $An get declared?

      Well, I don't really understand the code fragment you posted but, maybe

       print $An->{id}[0];

      Try using Data::Dumper to see the contents of $An