title: How to read file in Perl and if it doesn't exist create it?
body: <p>In Perl, I know this method :</p>
  
  <pre><code>open( my $in, "&lt;", "inputs.txt" );
  </code></pre>
  
  <p>reads a file but it only does so if the file exists.</p>
  
  <p>Doing the other way, the one with the +:</p>
  
  <pre><code>open( my $in, "+&gt;", "inputs.txt" );
  </code></pre>
  
  <p>writes a file/truncates if it exists so I don't get the chance to read the file and store it in the program.</p>
  
  <p>How do I read files in Perl considering if the file exists or not?</p>
  
  <p>Okay, I've edited my code but still the file isn't being read. The problem is it doesn't enter the loop. Anything mischievous with my code?</p>
  
  <pre><code>open( my $in, "+&gt;&gt;", "inputs.txt" ) or die "Can't open inputs.txt : $!\n";
  while (&lt;$in&gt;) {
      print "Here!";
      my @subjects    = ();
      my %information = ();
      $information{"name"}     = $_;
      $information{"studNum"}  = &lt;$in&gt;;
      $information{"cNum"}     = &lt;$in&gt;;
      $information{"emailAdd"} = &lt;$in&gt;;
      $information{"gwa"}      = &lt;$in&gt;;
      $information{"subjNum"}  = &lt;$in&gt;;
      for ( $i = 0; $i &lt; $information{"subjNum"}; $i++ ) {
          my %subject = ();
          $subject{"courseNum"} = &lt;$in&gt;;
          $subject{"courseUnt"} = &lt;$in&gt;;
          $subject{"courseGrd"} = &lt;$in&gt;;
          push @subjects, \%subject;
      }
      $information{"subj"} = \@subjects;
      push @students, \%information;
  }
  print "FILE LOADED.\n";
  close $in or die "Can't close inputs.txt : $!\n";
  </code></pre>