note
rjt
<p>While my esteemed predecessors have done a good job of answering your direct questions, perhaps I can shed some light on a few stylistic questions you didn't ask, but may still find informative.</p>
<p>The line:</p>
<c> open FILELIST, ">$filelist";</c>
<p>is problematic for a couple of reasons:</p>
<ul>
<li>The <c>open</c> might fail (for example, if the file does not exist), so you need to check the return.</li>
<li>The two-argument <c>open</c> (with the append (<c>></c>) symbol in the same string as the filename) is a potential security risk; see the old [id://131085] discussion for more info.</li>
<li>The filehandle, <c>FILELIST</c>, is in the global symbol table. It's better form to create a lexical variable instead with [doc://my].</li>
</ul>
<p>So, instead, I would write:</p>
<p><b>(UPDATED</b> thanks to [AnomylousMonk]'s good catch of a very carelessly chosen variable name)</p>
<c> open my $fh, '>', $filelist
or die "Can't open $filelist: $!";</c>
<p>If it fails, the program will exit with an informative error code. You could instead wrap the <c>open</c> call in an <c>if</c> statement if you want to do something else.</p>
<p>Purely personal preference on this next one, but your entire <c>foreach { ... } </c> loop could be more concisely written:</p>
<c> print $fh $_ for @files;</c>
1022103
1022103