title: Perl - Using an Array on a Config txt file
body: <p>So I have a text file with four sets of data on a line, such as <code>aa bb username password</code>. So far I have been able to parse through the first line of the file using substrings and indices, and assigning each of the four to variables.</p>
  
  <p>My goal is to use an array and chomp through each line and assign them to the four variables, and than to match an user inputted argument to the first variable, and use the four variables in that correct line.</p>
  
  <p>For example, this would be the text file:</p>
  
  <pre><code>"aa bb cc dd"
  "ee ff gg hh"   
  </code></pre>
  
  <p>And depending on whether the user inputs "aa" or "ee" as the argument, it would use that line's set of arguments in the code.</p>
  
  <p>I am trying to get up a basic array and chomp through it based on a condition for the first variable, essentially.</p>
  
  <p>Here is my code for the four variables for the first line, but like I said, this only works for the first line in the text file: </p>
  
  <pre><code>local $/;
  open(FILE, $configfile) or die "Can't read config file 'filename' [$!]\n";  
  my $document = &lt;FILE&gt;; 
  close (FILE);  
  
  
  
  my $string = $document;
  my $substring = " ";
  
  my $Index = index($string, $substring);
  my $aa = substr($string, 0, $Index);
  my $newstring = substr($string, $Index+1);
  
  my $Index2 = index($newstring, $substring); 
  my $bb = substr($newstring, 0, $Index2);
  my $newstring2 = substr($newstring, $Index2+1);
  
  my $Index3 = index($newstring2, $substring);
  my $cc = substr($newstring2, 0, $Index3);
  my $newstring3 = substr($newstring2, $Index3+1);
  
  my $Index4 = index($newstring3, $substring);
  my $dd = substr($newstring3, 0, $Index4);
  </code></pre>