text: Q:
  
  Perl Split File Into Lines and Variables
  
  I am currently splitting a Perl file which holds some user/password information and am doing it successfully, but am not satisfied with my code. I am sure there is a better way to do it in Perl (I am a beginner). If someone could come up with a slicker way that would be great!
  my $i = 1;
  my $DB;
  my $DBHOST;
  my $DBUSER;
  my $DBPASS;    
  my $filename = "some_file";
  open(my $fh, '<:encoding(UTF-8)', $filename)
      or die "Could not open file '$filename' $!";
  
  while (my $row = <$fh>) {
      chomp $row;
      if ($i == 1) {
          $DB = (split /=/, $row)[1];
      }
      if ($i == 2) {
          $DBHOST = (split /=/, $row)[1];
      }
      if ($i == 3) {
          $DBUSER = (split /=/, $row)[1];
      }
      if ($i == 4) {  
          $DBPASS = (split /=/, $row)[1];
      }
      $i++;
  }
  
  A:
  
  map() is pretty handy for things like this:
  my ($DB, $DBHOST, $DBUSER, $DBPASS) = map {$_ =~ /.*?=(.*)/} <$fh>;
  
  What's happening:
  
  map() operates on lists, so it treats <$fh> as one
  for each element in the list (a file line in this case), assign it into the default variable ($_)
  then, capture the part of the line we want using regex, return it, and assign it to the relevant variable on the left-hand-side (on each iteration of the file, each one of the receiving variables are shifted as well)
  the regex operates as follows:
  /
      .*? # ignore everything, non greedy until we match a
      =   # our delimiter
      (   # begin capture
      .*  # capture everything until end of line (less the newline char)
      )   # end capture
  /
  
  Note that this solution will iterate all the way through the whole file, even after all four of the variables are populated (as does the way you've done it in your OP).
  Also note that there's no error checking here, so if a value isn't captured, you'll get warnings related to undefined variables.
  
  