The above still has syntax errors; instead of

if ((($current_mth == 1) && ($last_day_current_mth == 31)) {

you mean

if (($current_mth == 1) && ($last_day_current_mth == 31)) {

There is an unbalanced parenthesis.

The bareword warning mentioned in my first post was due to your omitted block. The prototype system (see Prototypes in perlsub) is only in force when you use new-style calls (no &), though that you input changed after including makes me think you might be using that incorrectly. Is there a compelling reason to use prototypes here? In general, you are better off not using them unless you are doing something clever. You do not appear to be doing that here, so I would suggest removing it - they likely don't do what you think they do anyway. Additionally, prototypes cannot be enforced unless the subroutine declaration precedes any invocation of the method.

When I compile the posted code, there are 6 undeclared variables: $unlinkCountTotal, @deleted_files, $task, $logger, $current_mth, and $last_day_current_mth. Based upon how you are using them, $task and $logger are objects which means you are using packages that you have not told us about. None of these variables are declared within the subroutines, which means you are either using closures or globals - I'm guessing the latter. Depending on the code that surrounds these methods, it is quite possible the actual variables referenced by those names change when you are cutting/pasting the code between the two subroutines. I can't know without seeing the surrounding code.

The following code creates a file and then unlinks it. I wrote it by removing all the code you had that required additional variables and guessing intent. There are a number of additional stylistic issues that I am ignoring here.

#!/usr/bin perl use strict; use warnings; my $name = 'junk'; open my $fh, '>', $name or die "Open fail: $!"; print $fh 'some content'; close $fh; file_handler($name); sub threeYrExpiration($) { my $abs_filename = $_[0]; my $unlinkStatus = unlink("$abs_filename"); if ($unlinkStatus == 1) { warn "Success"; } else { warn "Fail"; } } sub file_handler { my ($abs_filename) = @_; threeYrExpiration($abs_filename); }

Take this code and systematically add elements that appear in your total script until it breaks. Then post that code. As I said in the original response, the issue is not in the code you posted.


In reply to Re^5: Delete file from sub call within another sub by kennethk
in thread Delete file from sub call within another sub by begood321

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.