Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with this mult-dimensional array 2

Status
Not open for further replies.

cdlvj

MIS
Nov 18, 2003
678
US
Code:
my @data;
@data = ( 
    ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[    1,    2,    5,    6,    3,  1.5,    1,     3,     4],
[    1, 2, 5, 6, 3, 1.5, 1, 3, 4 ]
  );
This is from the GD::Graph, and I cannot find anything in Perl pages about this syntax.

Ran debugger and cannot extract any of the elements, just keep getting the pointers to the array.
How would you use the push to populate the values of @data?

Thanks in advance.

 
Like so

Code:
my @data;
@data = (
    ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[    1,    2,    5,    6,    3,  1.5,    1,     3,     4],
[    1, 2, 5, 6, 3, 1.5, 1, 3, 4 ]
  );
  
print $data[0][1] . "\n"; # print second element of anonymous array 0
push @{$data[0]}, "10th"; # push a new element on the end of anonymous array 0
print $data[0][9] . "\n"; # print the newly pushed element
push @data, [10, 11, 12 ,13]; # create a new anonymous array inside @data
print "$_\n" foreach @{$data[3]}; # print the values of the new anonymous array
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top