This reply does not deal with The Original Question.

It seems you are having some shortage of whitespace, and clearly are not running your code under warnings pragma.

$cutover=(split /:/,$time)[0]; if ($date=~/\s(\d{2})/){ $hour=$1; } ... if ($hour > $cutover){

In case $date is not formatted correctly or is undefined, $hour would be undefined in the if condition. That would cause the backup not to be moved.

If warnings pragma were in effect, above would have generated an "uninitialized value" error message (assuming variables had been properly declared) when $date =~ /\s(\d{2})/ fails, indicating problem in expected date format or value.

$date=DateCalc("$date","+24 hours"); ###Takes 2min out of +2:30min.

Why is there a need to quote $date above? By the associated comment, do you mean adding 24 hours to a date string causes half hour times to be shifted back by 2 minutes?

$date=&UnixDate($date,"%Y-%m-%d");

Why is UnixDate sub being called as &UnixDate() not just UnixDate() -- note the lack of '&'? At least be consistent.

if (defined ${$report{$host}{$pol}{$sched}{$date}}){ ${$report{$host}{$pol}{$sched}{$date}}=${$report{$host}{$p +ol}{$sched}{$date}}+$error; }else{ ${$report{$host}{$pol}{$sched}{$date}}=$error; }

(Damn!) Are you sure that the date field referenced in above hash is really a scalar reference, not just a plain scalar? In the if branch, what is it that you want to achieve by using + operator? Besides, won't you agree that accessing the date field as above is rather a pain?

Without warnings pragma in effect, in the first branch, the date field would be the value of arithmetic addition of the date field & $error. + is only a arithmetic operator (barring any intentional overloading and outside of regular expressions) which causes any string to be added (as above) to evaluate to zero. . is the concatenation operator.

Now, if warnings were in effect, you would have gotten an error message indicating that the operands of + are not numeric (as appropriate).

Above can be rewritten in many ways. Here is one version assuming (a) the date field in %report is really a scalar reference, and (b) in the if branch, you want to concatenate $error with the date field ...

my $rep_date = $report{$host}{$pol}{$sched}{$date}; if ( defined ${ $rep_date } ) { ${ $rep_date } .= $error; } else { ${ $rep_date } = $error; } # # ... or ... #${ $rep_date } = # defined ${ $rep_date } ? ${ $rep_date } . $error # : $error # ;

Please study some introductory material -- including but not limited to, in not much of an order -- Learning Perl and Intermediate Perl books, perlintro, perldsc, perlsub, perlreftut, perlop.


In reply to Re: Changing dates by parv
in thread Changing dates by snantz

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.