http://qs321.pair.com?node_id=1179742


in reply to Re: Some help with my project:
in thread Some help with my project:

In this code also if you add one more if condition before doing this calculation,
it will prevent these kind of error if future
if ($used){ my $monit_percentual = ( $avail / $avail+$used ) * 100 ; my $final_used = $used / 1000 ; my $final_avail = $avail / 1000 ; print "$monit is a $fs_type filesystem who has $final_used space u +sed (in MB) and $final_avail of avalible space (in MB too) \n" ; #comparacion con el porcentaje de $monit_percentual if ($monit_percentual < $warn) { print "Less of the $warn % of the space of the filesystem +$monit is avalible for use, consider uninstall unused software \n" ; } elsif ($monit_percentual eq $warn) { print "Be carefull, exactly the $warn % of the space of $m +onit is usable, consider uninstall unused software \n" ; } else { print "There is a $monit_percentual % of avarible space of + the disk \n" ; } }else{ print "Some message\n"; }

Replies are listed 'Best First'.
Re^3: Some help with my project:
by marto (Cardinal) on Jan 17, 2017 at 14:50 UTC
    my $monit_percentual = (  $avail  /  $avail+$used  ) * 100 ;

    "it will prevent these kind of error if future"

    If you want to prevent errors be aware of perlop "Operator precedence and associativity".

    use strict; use warnings; my $avail = 1; my $used = 1; my $testa = ( $avail / $avail + $used ) * 100; my $testb = ( $avail / ( $avail + $used ) ) * 100; print "testa: $testa\ntestb: $testb\n";