title: Perl: How to print a line to a file from within a while loop?
body: <p>I have a very basic perl script which prints the next line in a text file after matching a search pattern.</p>
  
  <pre><code>@ARGV = &lt;dom_boot.txt&gt;;
  while ( &lt;&gt; ) {
      print scalar &lt;&gt; if /name=sacux445/;
  }
  </code></pre>
  
  <p>Which works, However I would like to capture the output into a file for further use, rather than printing it to <code>STDOUT</code>.
  I'm just learning (slowly) so attempted this:</p>
  
  <pre><code>my $fh;
  my $dom_bootdev = 'dom_bootdev.txt';
  
  open ($fh, '&gt;', $dom_bootdev) or die "No such file";
  
  @ARGV = &lt;dom_boot.txt&gt;;
  while ( &lt;&gt; ) {
      print $fh &lt;&gt; if /name=sacux445/;  
  }
  
  close $fh;
  </code></pre>
  
  <p>But I get a syntax error.</p>
  
  <blockquote>
    <p>syntax error at try.plx line 19, near "&lt;>"</p>
  </blockquote>
  
  <p>I'm struggling to figure this out. I'm guessing it's probably very simple so any help would be appreciated.</p>
  
  <p>Thanks,
  Luke.</p>