lbrandewie has asked for the wisdom of the Perl Monks concerning the following question:

Hey Monks,

I've got a puzzler. I moved an app from Windows to Linux (CentOS 8 to be specific) to solve library problems. I've got a section of code that tries to determine if an email should be sent. The code looks like this:

if ($out eq "D") { # not responding to pings if ($lastmailed{"$email|$targ"} <= ($min - $squelch)) { $mailer = psMailer->new(); $mailer->to($email); $mailer->from($emailfrom); $mailer->subject($emailsubject); $mailer->body("Asset $targ is not responding to pings."); $mailer->assetname($targ); $mailer->send(); } }

psMailer is a simple sendmail interface. That's not the problem. The $min var is calculated as int(time() / 60), so it should always be an int. The $squelch value comes from a settings file. If it is set to 10, the intent is that 10 minutes should pass between emails on a given topic.

This works in Windows, but in Linux the consistent result is that eleven minutes pass between the emails.

I don't get it. Do you have any ideas? TIA,

Lars

p.s. The perl version on CentOS 8 is 5.26.3. The version I was running in Windows was 5.28.1 (Activestate). I'm on Windows 7 x64.

Replies are listed 'Best First'.
Re: Windows / Linux puzzler
by Veltro (Hermit) on Mar 23, 2020 at 12:34 UTC

    I can't spot the exact problem but I suspect a floating point problem. I suggest you follow the advice from perldoc int and use the POSIX::floor instead:

    From the docs:

    ...For example, int(-6.725/0.025) produces -268 rather than the correct -269; that's because it's really more like -268.99999999999994315658 instead. Usually, the sprintf, printf, or the POSIX::floor and POSIX::ceil functions will serve you better than will int.

      Hmmmmmmmmmmmmmmmmmmmm...

        Hmmmmmmmmmmmmmmmmmmmm...

        I think Veltro's point is likely irrelevant if both the Windows perl and Linux perl report the same value for $Config{nvsize}.
        But if the nvsize differs between the 2 perls, then it's a different matter. For example:
        On perl-5.30.0 whose nvsize is 8 (and whose nvtype is 'double': C:\>perl -V:nvsize nvsize='8'; C:\>perl -le "print int(1000 * 0.001);" 1 On perl-5.30.0 whose nvsize is 12 or 16 (and whose nvtype is 'long dou +ble'): C:\>perl -V:nvsize nvsize='16'; C:\>perl -le "print int(1000 * 0.001);" 0
        Does perl -V:nvsize report the same value on both machines ?
        Does perl -V:nvtype report the same type on both machines ?

        Update:
        It's probably worth mentioning that both of those perls are correct in what they're doing.
        The double that most closely represents the value 0.001 is actually slightly greater than 0.001
        The long double that most closely represents the value 0.001 is actually slightly less than 0.001.

        Cheers,
        Rob
Re: Windows / Linux puzzler
by Anonymous Monk on Mar 23, 2020 at 02:09 UTC

    I hope I can contribute something, although I definitely don't know exactly whats going on.

    First suspicion: the time() function is not the same on both platforms.

    Second suspicion: the settings file for $squelch doesn't have exactly what you think.

    Last suggestion: work around by subtracting 1 from squelch or adding 1 to $min, or the other way round.

    Probably not exactly what you're looking for but I hope it may help.

    Cheers, JAWPH

      I like your first suspicion more than your second. I'm pretty sure what's in that file. I will investigate. The notion of a workaround has also occurred to me. Thanks,

      Lars

        I like your first suspicion more than your second.

        Sorry, but personally I find the AM's first suggestion less likely, time should be portable across platforms, and it being off by an entire minute would be an obvious problem. I do think you should investigate the values of your variables on both platforms though: output them via Data::Dumper with $Data::Dumper::Useqq=1; or Data::Dump (see also the Basic debugging checklist).

A reply falls below the community's threshold of quality. You may see it by logging in.