title: Reading text file into array in perl
body: <pre><code>    my $file = '/var/tmp/temp_data.txt';      ##################### File for reading
      open(FILE, '&lt;:encoding(UTF-8)', $file) || die("Unable to open file");
      my @fieldss = &lt;FILE&gt;;
      close(FILE);
      chomp @fieldss;
  
      my @fields = split(':', @fieldss);####################### Splitting the lines in file ##############
  ####################################### Dereference ############################
      my $names = $fields[0];
      my $rate = $fields[1];
      my $no_of_days = $fields[2];
      my $total_salary = $fields[3];
      my $total = $fields[4];
      my $basic = $fields[5];
      my $da = $fields[6];
      my $hra = $fields[7];
      my $ot_hallowance = $fields[8];
      my $gross = $fields[9];
      my $epf = $fields[10];
      my $nett = $fields[11];
  
      print "$names\n $rate\n";
  
          foreach $names (@fields) {
                  my $dbh = "DBI:$platform:$database:$host:$port";
                  my $connect = DBI-&gt;connect($dbh, $user, $pw) || die $DBI::errstr;
                  $query = "SELECT * FROM salary WHERE name IN('sssss', 'ffffff', 'dddddd', 'ddededed', 'garaead', 'adgfdfg', 'gadfredg')";
                  my $sth = $connect-&gt;prepare($query);
                  $sth-&gt;execute() || die $DBI::errstr;
  
                  my @data2;
                  while (@data2 = $sth-&gt;fetchrow_array()) {
                      my $name = $data2[0];
                      my $email = $data2[1];
  
                          if ($names eq $name) {  ######################### Comparing names in file and database ########################
  </code></pre>
  
  <p>The above code is to read the text file and data get split using split function. My problem is I am making mistake at reading and splitting the file. I got 504 error while running the code, I think it is because of calling the database for every line in text file. Thanks for your help.</p>