in reply to Re^3: eval not working the way I expected?
in thread eval not working the way I expected?

Please always say what the error messages actually are.
  • Comment on Re^4: eval not working the way I expected?

Replies are listed 'Best First'.
Re^5: eval not working the way I expected?
by convenientstore (Pilgrim) on Jan 10, 2008 at 18:10 UTC
    There was actually flow in my logic.. so I corrected and works now
    I still don't understand why eval { } || 0 did not work though
    for (sort keys %totalcalls)
    {
    
          my $start_i_f = ($start{$_}) ? $start{$_} : 0;
          $report_stop{$_} = sprintf("%.2f", ( ( $stop_inbound{$_} / 60000 ) / $stop{$_})) if $stop_inbound{$_};
          if (defined $crank{$_}) {
              $report_ccr{$_} = sprintf("%.2f" , ( ( $start_i_f / ($totalcalls{$_} - $crank{$_}) ) * 100 ));
              $report_asr{$_} = sprintf("%.2f" , ( ( $start_i_f / $totalcalls{$_}) * 100 )); 
          } else {
              $report_asr{$_} = sprintf("%.2f" , ( ( $start_i_f / $totalcalls{$_}) * 100 ));
              
          }
    }    
    
    

      I still don't understand why eval { } || 0 did not work though

      eval doesn't affect warnings. And the warning occurred during the division, not after the eval was completed.

      >perl -we"my $x; my $q = eval { $x / 4 } || 0; Use of uninitialized value in division (/) at -e line 1. >perl -we"my $x; my $q = eval { ($x||0) / 4 }; >perl -we"my $x; my $q = ( $x / 4 ) || 0; Use of uninitialized value in division (/) at -e line 1. >perl -we"my $x; my $q = ( ($x||0) / 4 );
        I was wish eval can wrap even the warnings but I guess that's not the purpose of the eval
        Do you guys normally run perl scripts that's written for production w/out -w ?
        I don't think having people seeing perl warning message is professional looking.. that's just my opinion