Perl Data Structures - Arrays of Arrays
Creating Arrays of Arrays:
Method 1:
@array=(["apple","orange"],["Mango","Banana"],["Papaya","Peach"]);
print $array[0][1];
Method 2:
$array[0] = ["apple","orange"];
$array[1] = ["Mango","Banana"];
$array[2] = ["Papaya","Peach"];
print $array[0][1];
Method 3:
@array1 = qw("apple","orange");
@array2 = qw("Mango","Banana");
@array3 = qw("Papaya","Peach");
$array[0] = \@array1;
$array[1] = \@array2;
$array[2] = \@array3;
print $array[0][1];
Method 4:
@{$array[0]} = ("apple","orange"); @{$array[1]} = ("Mango","Banana"); @{$array[2]} = ("Papaya","Peach"); print $array[0][1];
Method 5:
for $out (0..4) { for $in (0..4) { $array[$out][$in] = 1; } } print $array[0][1];
Method 6:
for $out (0..4) { push @array, [1,1,1,1]; }print $array[0][1];
Method 7:
@array=(["apple","orange"],["Mango","Banana"],["Papaya","Peach"]);
push @{$array[0]}, "Watermelon";
print $array[0][2];
0 Comments:
Post a Comment
Note: only a member of this blog may post a comment.
<< Home