in reply to Re: Print name of array
in thread Print name of array

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"; }

Replies are listed 'Best First'.
Re^3: Print name of array
by Jenda (Abbot) on Dec 06, 2011 at 13:48 UTC

    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
Re^3: Print name of array
by choroba (Cardinal) on Dec 06, 2011 at 13:24 UTC
    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
Re^3: Print name of array
by Taulmarill (Deacon) on Dec 06, 2011 at 13:51 UTC
    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.