<html>
<body>
So many ways to do the same thing in perl!<br><br>
I would probably have gone:-<br><br>
<tt> opendir (DIR, "$my_directory")<br>
or die("could not open DIR as $my_directory
Error: $!");<br><br>
@dir = readdir DIR;<br><br>
foreach (@dir)<br>
{<br>
chomp;<br><br>
if (m/^\+\w/)<br>
{<br>
push (@del_files, $_);<br>
}<br>
else<br>
{<br>
push (@ctr_file, $_);<br>
}<br>
}<br><br>
foreach (del_files)<br>
{<br>
unlink ($my_director/$_) or die("unlink failed
$!);<br>
}<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>
foreach (del_files)<br>
{<br>
$status = system("rm -f
$my_director/$_");<br>
die unless $status == 0;<br>
}<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 "+" and put them in a 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 "\n" 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
&& '/', "\n") }, $tmp_dir;<br><br>
#find all files starting with a plus<br>
foreach (@tmp) {<br>
<br>
$_ =~ s/$tmp_dir\/// ; # remove the path to the input
working dir so only <br>
# the files and directories in the working dir are used <br>
$_ =~
s/\/$//; #remove trailing
"/"<br>
# /^\+\w+/i filter all files starting with
"+" <br>
if ($_ =~ /^\+\w+/i ){ push(@del_files, $_); $_ =
"0"; } # filter and pass files starting with + to @del_files
for removale <br>
<br>
#print "$_";<br>
if ($_ ne "0"){<br>
push(@ctr_file ,
"$_");<br>
print "$_";<br>
}<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>