I have a bunch of files with garbage names, but they can be identified by their header.<br>In bash I can say<br><br>x=0<br>pattern=&quot;pattern&quot;<br>files=`grep -l $pattern list-of-files`<br><br>for this in $files do;
<br>&nbsp;&nbsp; if [ $x -eq 0 ]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sed s/\~/\\r\\n/g $files &gt; name.txt<br>&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sed s/\~/\\r\\n/g&nbsp; $files &gt; name.txt$x<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x=`expr $x + 1`<br>&nbsp;&nbsp; fi<br>done<br><br><br>But I want learn how to do this in perl
<br>so it would be something like (and please pardon my ignorance)<br><br>my $x = 0;<br>my $pattern = &quot;pattern&quot;;<br><br>open DH, &quot;path&quot; or die;<br>my @files = (readdir DH);<br>my @found = grep($pattern, @files);
<br>for my $source (@found) {<br>my destination = &quot;$source.new&quot;<br>&nbsp;&nbsp; open INPUT, &quot;&lt;$source&quot; or die;<br>&nbsp;&nbsp; open OUTPUT &quot;&gt;$destination&quot; or die;<br>&nbsp;&nbsp; while (&lt;INPUT&gt;) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s/\176/\012\015/g;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print OUTPUT $_;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rename $destination, $source;<br>&nbsp;&nbsp; }<br><br>}<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br><br>-- <br>In vino veritas.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[In wine there is truth.]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- Pliny