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="pattern"<br>files=`grep -l $pattern list-of-files`<br><br>for this in $files do;
<br> if [ $x -eq 0 ]<br> sed s/\~/\\r\\n/g $files > name.txt<br> else<br> sed s/\~/\\r\\n/g $files > name.txt$x<br> x=`expr $x + 1`<br> 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 = "pattern";<br><br>open DH, "path" or die;<br>my @files = (readdir DH);<br>my @found = grep($pattern, @files);
<br>for my $source (@found) {<br>my destination = "$source.new"<br> open INPUT, "<$source" or die;<br> open OUTPUT ">$destination" or die;<br> while (<INPUT>) {<br> s/\176/\012\015/g;
<br> print OUTPUT $_;<br> rename $destination, $source;<br> }<br><br>}<br><br><br> <br><br>-- <br>In vino veritas.<br> [In wine there is truth.]<br> -- Pliny