in reply to Re: Delete file from sub call within another sub
in thread Delete file from sub call within another sub
Hi Kenneth,
Thanks for your advice. However, I think you missed my point. If I change my code to:
sub threeYrExpiration { my $abs_filename = $_[0]; my $unlinkStatus = unlink("$abs_filename"); if ($unlinkStatus == 1) { $unlinkCountTotal++; $abs_filename =~ s#.*WORKAREA\/[^\/]*##; push (@deleted_files, $abs_filename); $task->AddFile("$abs_filename", "Deleted by content expiration + report"); $logger->info("File to be deleted added to job: $abs_filename" +); } else { $logger->info("File to be deleted \"$abs_filename\" failed. Re +ceived $unlinkStatus instead of 1."); $task->CallBack(1, "Error Deleting expired file"); } }
It works, which is good. However, I have another sub which does similar (using same variables) but has differences in processing. Hence the reason for wanting to use another method calling sub from within another sub as seen below. So basically using the 2 subs code would look similar to:
sub file_handler { my ($abs_filename) = @_; if ((($current_mth == 1) && ($last_day_current_mth == 31)) { + threeYrExpiration($abs_filename); } else { sevenYrExpiration($abs_filename); } } # End of sub file_handler sub threeYrExpiration { my $abs_filename = $_[0]; my $unlinkStatus = unlink("$abs_filename"); if ($unlinkStatus == 1) { $unlinkCountTotal++; $abs_filename =~ s#.*WORKAREA\/[^\/]*##; push (@deleted_files, $abs_filename); $task->AddFile("$abs_filename", "Deleted by content expiration + report"); $logger->info("File to be deleted added to job: $abs_filename" +); } else { $logger->info("File to be deleted \"$abs_filename\" failed. Re +ceived $unlinkStatus instead of 1."); $task->CallBack(1, "Error Deleting expired file"); } } sub sevenYrExpiration { ... ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Delete file from sub call within another sub
by kennethk (Abbot) on Nov 29, 2010 at 17:27 UTC | |
by begood321 (Novice) on Nov 29, 2010 at 18:48 UTC | |
by kennethk (Abbot) on Nov 29, 2010 at 19:44 UTC |