Tuesday, 31 January 2023

Perl Data Structures - Accessing Arrays of Arrays

Method 1:

@array=(["apple","orange"],

               ["Mango","Banana"],

               ["Papaya","Peach"]

);

 

$arrayref = $array[1];

 print ${$arrayref}[1];


Method 2:

print ${array[1]}->[1];

Method 3:

print $array[1]->[1];

Method 4:

print $array[1][1];

Method 5:

Using For Loop:

for(my $a = 0; $a <= $#array; $a++)
{  
   for(my $b = 0; $b <= $#array ; $b++)
   {
      print "$array[$a][$b] ";
   }
   print "\n";
}

Method 6:

print  @{$array[0]}[1], "\n";
print  @{$array[1]}[0], "\n";
print  @{$array[2]}[2], "\n";

 

kaavannan blogspot

Labels:

0 Comments:

Post a Comment

Note: only a member of this blog may post a comment.

<< Home