Johnstone, Colin wrote:
Gidday All,

Previous email was wrong this is the correct version

I want to use the unlink command to programmatically delete files.

I have modified this code snippet but it no longer works, I suspect that
it's because unlink returns the number of deleted files.

my $cmd = qq[unlink $srcFile];
$debug->printlog("command: $cmd");
my $cmdResult = `$cmd 2>&1`;
$debug->printlog("result: $cmdResult");
if ($cmdResult =~ /^\s*$/) {
$cmdResult = "Successful file deletion." if ($cmdResult =~
/^\s*$/); $comment = "DELETION COMMAND: $cmd\nDELETION RESULT: $cmdResult";
$debug->printlog("REGEN $pid: Regen " . &basename($file) .
"\n$comment"); } else {
$errorComment = "ERROR: " . &basename($file) . " deletion
failed:\n";
$errorComment .= " Cmd: $cmd\n Result: $cmdResult\n";
$debug->printlog("$errorComment");
&abort(1, "$errorComment");
}


So want Im trying to achieve is delete file
Write the successful deletion or error to the log file then continue.
But it executes the else clause each time.

Regards
Colin

Colin Johnstone Interwoven Teamsite Analyst Programmer eGovernment Delivery Team
QLD Department of Employment and Training
Telephone (07) 3244 6281
Fax (07) 3244 6265
Address Southbank Institute of TAFE - Kangaroo Point Campus
Visit: http://www.trainandemploy.qld.gov.au/




This E-Mail is intended only for the addressee. Its use is limited to
that intended by the author at the time and it is not to be distributed
without the author's consent. Unless otherwise stated, the State of
Queensland accepts no liability for the contents of this E-Mail except
where subsequently confirmed in writing. The opinions expressed in this
E-Mail are those of the author and do not necessarily represent the
views of the State of Queensland. This E-Mail is confidential and may be
subject to a claim of legal privilege.

If you have received this E-Mail in error, please notify the author and
delete this message immediately.




Colin Johnstone Interwoven Teamsite Analyst Programmer eGovernment Delivery Team
QLD Department of Employment and Training
Telephone (07) 3244 6281
Fax (07) 3244 6265
Address Southbank Institute of TAFE - Kangaroo Point Campus
Visit: http://www.trainandemploy.qld.gov.au/




[EMAIL PROTECTED]:~$ perl -e '$blah = `unlink hi`; print "$blah"' [EMAIL PROTECTED]:~$

hmm, hi existed and was deleted, yet $blah is undefined or null even, this means it's not returning how many files it deleted :) remember to add prints to aid in debugging when needed (maybe cmdResult IS being defined). My suggestion is to either use unlink() or change 'if ($cmdResult =~ /^\s*$/) {' to 'if (!($cmdResult)) {' and try again. Using the * quantifier has been known to cause problems.

--K-sPecial

[ http://xzziroz.freeshell.org
  irc://xzziroz.dtdns.net       ]



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to