title: reading text file and writing to two dimensional array in perl?
body: <pre><code>#!/usr/bin/perl
  
  use strict;
  use warnings;
  use utf8;
  use open ':encoding(UTF-8)', ':std';
  use List::Util qw( sum );
  
  my $filename =  'data1.txt';
  
  open(my $fh, '&lt;:encoding(UTF-8)', $filename)
      or die "Could not open file '$filename' $!";
  
  while (my $row = &lt;$fh&gt;) {
      chomp $row;
      print "$row\n";
  }
  
  my $filename2 = 'data2.txt';
  
  open(my $fh2, '&lt;:encoding(UTF-8)', $filename2)
      or die "Could not open file '$filename2' $!";
  
  while (my $row = &lt;$fh2&gt;) {
      chomp $row;
      print "$row\n";
  }
  
  my @last = ();
  
  my %grades = (
      Ahmet =&gt; {
          quiz1 =&gt; 97,
          quiz2 =&gt; 67,
          quiz3 =&gt; 93,
      },
      Su =&gt; {
          quiz1  =&gt; 88,
          quiz2  =&gt; 82,
          quiz3  =&gt; 99,
      });
  
  my %sum;
  
  for my $name (keys %grades){
      $sum{$name} = sum(values %{ $grades{$name} });
  }
  
  for my $name (sort { $sum{$a} &lt;=&gt; $sum{$b} } keys %sum){
      push @last, "$name: $sum{$name}\n";
  }
  
  my %grades2 = (
      Bugra =&gt; {
          quiz1 =&gt; 33,
          quiz2 =&gt; 41,
          quiz3 =&gt; 59,
      },
      Lale =&gt; {
          quiz1 =&gt; 79,
          quiz2 =&gt; 31,
          quiz3 =&gt; 62,
      },
  );
  
  my %sum2;
  for my $name (keys %grades2){
      $sum2{$name} = sum(values %{ $grades2{$name} });
  }
  
  for my $name (sort { $sum2{$a} &lt;=&gt; $sum2{$b} } keys %sum2){
      push @last, "$name: $sum2{$name}\n";
  }
  
  my @last1 = sort { lc($a) cmp lc($b) } @last;
  
  print @last1;
  </code></pre>
  
  <p>This is my code. I want to take values from a text file something like ( marry 10 65 23) and write to a two dimensional array. I managed array separately end of the read text file it has to be seen like <code>grade1</code> and <code>grade2</code> for <code>data1.txt</code> and <code>data2.txt</code>. I can pull the values but I couldn't write to two dimensional array. Also result is correct.</p>