#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

    Problem comparing 2 floats


    Hi,

    I'm having trouble comparing 2 floats for a greater then status. The numbers are extracted from a log file using pattern matching and then compared against test number for greater than status. Here is the code:

    Code:
    foreach $logEntry ( @logstocount )
      {
        $logEntry =~ /^.*vs p=(\d\.\d+)\s.*$/;
        $probability = $1;
        if ( $probabilty > 0.005)
          { 
    	$spamCount++;
          }
        else
          {
    	$okCount++;
          }
        $totalCount++;
      }
    
    print "OK:    $okCount\n";
    print "SPAM:  $spamCount\n\n";
    print "Total: $totalCount\n";
    When I run the program $okCount always equals $totalCount and $spamCount equals 0 (all 3 counter variables are initialized with 0). I'm using an arbitrarily low probability for testing, so $spamCount should be quite high.

    Can anyone tell me wht I'm doing wrong?

    Thanks,
    Rob
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,930
    Rep Power
    1225
    Have you tried dumping out $probability to see what it holds? It may not hold what you think.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0
    I initially printed it to make sure the regexp was doing what I wanted it to do, and it was. The output is in the form of n.nnn, e.g., 0.250 or 0.025, etc (and even an occasional 1.000).
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    Originally Posted by caspersgrin
    Hi,
    Code:
    foreach $logEntry ( @logstocount )
      {
        $logEntry =~ /^.*vs p=(\d\.\d+)\s.*$/;
        $probability = $1;
        if ( $probabilty > 0.005)
          { 
    	$spamCount++;
          }
        else
          {
    	$okCount++;
          }
        $totalCount++;
      }
    
    print "OK:    $okCount\n";
    print "SPAM:  $spamCount\n\n";
    print "Total: $totalCount\n";
    Should have had a "use strict;" in there.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

IMN logo majestic logo threadwatch logo seochat tools logo