in reply to Changing dates
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.
|
|---|