in reply to Print name of array

What do you mean by the name of the array? Its index in the @AoA? To get it, you can just
for my $index (0 .. $#AoA) { print "$index\t@{ $AoA[$index] }\n"; }

Replies are listed 'Best First'.
Re^2: Print name of array
by Saved (Beadle) on Dec 06, 2011 at 13:22 UTC
    This prints the index number, and then the contents of the array.I was hoping to get the actual name.
    my @AoA = ( \@AdhLnk, \@MtrLnk, \@SltLnk, \@OthLnk, \@AdhDlk, \@MtrDlk +, \@SltDlk , \@OthDlk ); print "Output loop\n"; for my $index (0 .. $#AoA) { print "$index\t@{ $AoA[$index] }\n"; } foreach (@AoA) { print @{$_} . "_____________________________________________________ +________ __\n"; }

      Then it should have been a HoA:

      my %HoA = ( AdhLnk => \@AdhLnk, MtrLnk => \@MtrLnk, SltLnk => \@SltLnk +, OthLnk => \@OthLnk, AdhDlk => \@AdhDlk, MtrDlk => \@MtrDlk, SltDlk => \@SltDlk, OthDlk + => \@OthDlk ); print "Output loop\n"; for my $name (keys %HoA) { print "$name\t@{ $HoA{$name} }\n"; }

      And most probably there should not have been all those arrays in the first place.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

        Thank You, This helps. Have a gr8 dA
      And what would you return for this?
      @AoA = ([qw/Mercury Venus Earth Mars/], [qw/1 1 2 3 5 8 13 21/]);
      From where should Perl know it's planets and fibonacci?

      Update: Also consider

      @x = (1, 2, 3); *y = *x; my @AoA = (\@x, \@y);
      Is it @x or @y?
        my @AoA = ([qw/Mercury Venus Earth Mars/], [qw/1 1 2 3 5 8 13 21/]); for my $index (0 .. $#AoA) { print "$index\t@{ $AoA[$index] }\n"; }
        0 Mercury Venus Earth Mars 1 1 1 2 3 5 8 13 21
      A reference by itself does not know what variables points to the same data. This is because the array your reference points to does not have to be accessible through a normal array variable. There could also be multiple variables pointing to the same Data. The reference only knows, what type of data it points to and where that data is. If you need labels for those lists, you might want to use a Hash of Arrays.
Re^2: Print name of array
by ww (Archbishop) on Dec 06, 2011 at 19:44 UTC
    Maybe (well, maybe) OP is looking for
           \@AOA or \%foo

    This might be useful with a meaningful array-name; obviously, it won't help with poorly named (or, named-just-for-illusation) cases, not for anonymous arrays.