thanks for the alternative methode.<br><br>but why does this not work .....<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"){ <<<<<<<<<<<< why is this logic still creating "\ n" in the array .. it should only append to the array if $_ holds a valid path.
<br> push(@ctr_file , "$_");<br> print "$_";<br> }<br><br><div><span class="gmail_quote">On 6/29/06, <b class="gmail_sendername">Spike</b> <<a href="mailto:spikeh@mweb.co.za">spikeh@mweb.co.za
</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>
<div>
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></div><div><span class="e" id="q_10c1e6b417001ed0_1">At 2006/06/29 07:37 AM, you wrote:<br>
</span></div><div><blockquote type="cite" cite="http://"></blockquote></div><div><span class="e" id="q_10c1e6b417001ed0_3">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>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></span></div><div>
_______________________________________________<br>
Za-pm mailing list<br>
<a href="mailto:Za-pm@pm.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Za-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/za-pm" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://mail.pm.org/mailman/listinfo/za-pm</a></div>
</div><br>_______________________________________________<br>Za-pm mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Za-pm@pm.org">Za-pm@pm.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.pm.org/mailman/listinfo/za-pm" target="_blank">
http://mail.pm.org/mailman/listinfo/za-pm</a><br><br></blockquote></div><br><br clear="all"><br>-- <br>Gregory Machin<br><a href="mailto:greg@linuxpro.co.za">greg@linuxpro.co.za</a><br><a href="mailto:gregory.machin@gmail.com">
gregory.machin@gmail.com</a><br><a href="http://www.linuxpro.co.za">www.linuxpro.co.za</a><br><a href="http://www.exponent.co.za">www.exponent.co.za</a><br>Web Hosting Solutions<br>Scalable Linux Solutions <br><a href="http://www.iberry.info">
www.iberry.info</a> (support and admin)<br><br>+27 72 524 8096