You described your goal like this:
the script will run whether the arg is there or not and if its not, check the modification date of a file and if its a week old, run a certain sub.

I don't see any indication of trapping an error condition, so why do you have:  die "takes one arg"? If I understand your description, the idea is:

  1. If there is something in @ARGV, do something with that.
  2. else, if $file is older than 7 days, call a subroutine
  3. else exit (nothing to do, except may explain to the user why nothing was done).
If you feel compelled to put all that in one statement, I'd feel compelled to ask why. Spreading it out a bit does not create any problems, and does clarify the intent:
if ( @ARGV ) { do_something( shift ); } elsif ( -M $file > 7 ) { do_something_else(); } else { warn "Nothing to do ($file is recent, and you gave no arg to work +on)\n"; warn "Usage: $0 [optional_arg_that_does_what_exactly]\n"; } # default exit status will be "0" (success)
If the "nothing to do" condition should really be treated as a failure, use die instead of warn with the "Usage: ..." message. You would also use die (or Carp::croak) in your subroutines, or check their return values and die after the call, if necessary.

In reply to Re: shift or die unless by graff
in thread shift or die unless by joec_

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.