title: Writing contents of an array to txt file in perl
body: <p>The output I'm trying to achieve would look like this:</p>
  
  <p><code>Name  age gpa</code> </p>
  
  <p>for every element in each array, however when I write the contents of the array to a file it over writes somewhere and is display like this:</p>
  
  <pre><code>name1 name2 age1
  </code></pre>
  
  <p>Here's my code, all help (even on my coding style) is greatly appreciated. I've only displayed the parts of the code I think are necessary, if more is required for help please let me know.</p>
  
  <pre><code>sub get_name
  {
      printf("Name :");
      push(@get_name, &lt;STDIN&gt;); #taking name from user and putting it in @get_name array
      chomp(@get_name); #erasing newline from input
      #return @get_name;
  }       
  
  sub get_age
  {
      print "Age :";
      push(@get_age, &lt;STDIN&gt;); #taking name from user and putting it in @get_name array
      chomp(@get_age); #erasing newline from input
      #return @get_age;
  }       
  
  sub get_gpa
  {
      print "GPA: ";
      push(@get_gpa,&lt;STDIN&gt;);  #taking name from user and putting it in @get_name array
      chomp(@get_gpa); #erasing newline from input
      #return @get_gpa; #returning value may be unnecessary
  }       
  
  sub continue
  {
      print "Get student data: ";
       $stu_data = &lt;STDIN&gt;;
  
      if ($stu_data =~ m/[n]/)
      {
              print "\nEnter file name: "; $user_file = &lt;STDIN&gt;;
              open (FILE, "&gt;&gt;$user_file") or die $!;
              printf FILE "%-0.25s %3.3s %4.4s\n", @get_name, @get_age, @get_gpa;           #writing to user given file.
              exit;
  
      }
      elsif ($stu_data =~ m/[y]/)
      {       #possibly makes do while loop unnecessary
              &amp;get_name;
              &amp;get_age;
              &amp;get_gpa;
              &amp;continue;
      }
  
  
  }
  close FILE;
  </code></pre>