<html>
<body>
So many ways to do the same thing in perl!<br><br>
I would probably have gone:-<br><br>
<tt>&nbsp; opendir (DIR, &quot;$my_directory&quot;)<br>
&nbsp;&nbsp;&nbsp; or die(&quot;could not open DIR as $my_directory
Error: $!&quot;);<br><br>
&nbsp; @dir = readdir DIR;<br><br>
&nbsp; foreach (@dir)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; chomp;<br><br>
&nbsp;&nbsp;&nbsp; if (m/^\+\w/)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; push (@del_files, $_);<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; push (@ctr_file, $_);<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp; }<br><br>
&nbsp; foreach (del_files)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; unlink ($my_director/$_) or die(&quot;unlink failed
$!);<br>
&nbsp; }<br><br>
# assuming a unix type OS; I have often found that file manipulation is
one of the few places where a system call directly to the underlining OS
commands is better than the PERL commands. So maybe:-<br><br>
&nbsp; foreach (del_files)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; $status = system(&quot;rm -f
$my_director/$_&quot;);<br>
&nbsp;&nbsp;&nbsp; die unless $status == 0;<br>
&nbsp; }<br><br>
<br><br>
<br><br>
<br>
</tt>At 2006/06/29 07:37 AM, you wrote:<br>
<blockquote type=cite class=cite cite="">Hi<br>
I have been writing a script to pass a directory the remove all the files
starting with &quot;+&quot; and put them in a&nbsp; an array @del_files
and all the remaining in an array @ctr_file<br>
The problem Im having is that where the +FILE 's used to be I get blank
lines with &quot;\n&quot;&nbsp; in the @ctr_file, which I don't want .
<br><br>
find sub { push(@tmp
,$<a href="File::Find::name" eudora="autourl">File::Find::name</a>, -d
&amp;&amp; '/', &quot;\n&quot;) }, $tmp_dir;<br><br>
#find all files starting with a plus<br>
foreach (@tmp) {<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; $_ =~ s/$tmp_dir\/// ; # remove the path to the input
working dir so only <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# the files and directories in the working dir are used&nbsp; <br>
&nbsp;&nbsp;&nbsp; $_ =~
s/\/$//;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #remove trailing
&quot;/&quot;<br>
&nbsp;&nbsp;&nbsp; # /^\+\w+/i&nbsp; filter all files starting with
&quot;+&quot; <br>
&nbsp;&nbsp;&nbsp; if ($_ =~ /^\+\w+/i ){ push(@del_files, $_); $_ =
&quot;0&quot;; } # filter and pass files starting with + to @del_files
for removale <br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; #print &quot;$_&quot;;<br>
&nbsp;&nbsp;&nbsp; if ($_ ne &quot;0&quot;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; push(@ctr_file ,
&quot;$_&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;$_&quot;;<br>
&nbsp;&nbsp;&nbsp; }<br>
}<br><br>
<br>
Many thanks for you time<br>
Greg<br>
_______________________________________________<br>
Za-pm mailing list<br>
Za-pm@pm.org<br>
<a href="http://mail.pm.org/mailman/listinfo/za-pm" eudora="autourl">
http://mail.pm.org/mailman/listinfo/za-pm</a></blockquote></body>
</html>