in reply to weird problem with macports perl on apple m1/m2 based system

I don't have any Macs so I tested on a PC.

I modified your code to get rid of the evals. With some luck, this may fix your (unidentified) problem.

#!/usr/bin/env perl use strict; use warnings; use POSIX; use Tk; my %pid; %pid=( DCDC_A_51=>{cmd=>'22 46 5B', cu=>'51', desc=>'DC/DC output curren +t t30', unit=>'A', d=>2, formula=>sub{sprintf("%.2f", U1 +6(1,4)/16)}}, DCDC_V_51=>{cmd=>'22 46 5C', cu=>'51', desc=>'DC/DC output voltag +e t30', unit=>'V', d=>2, formula=>sub{sprintf("%.2f", U1 +6(25,253)/512)}, val=>'---'}, DCDC_W_51=>{ desc=>'DC/DC power output' +, unit=>'W', action=>sub{sprintf("%.0f", ($ +pid{DCDC_V_51}{val} * $pid{DCDC_A_51}{val}))}, val=>'---'} ); my $mw=MainWindow->new(); $mw->Button(-text=>" Test ", -command=>sub{test()}, -font=>'Helvet +ica 18 bold', -pady=>20)->pack(); MainLoop; sub test { $pid{DCDC_V_51}{val}=$pid{DCDC_V_51}{formula}->(); print $pid{DCDC +_V_51}{val} ."\n"; $pid{DCDC_A_51}{val}=$pid{DCDC_A_51}{formula}->(); print $pid{DCDC +_A_51}{val} ."\n"; $pid{DCDC_W_51}{val}=$pid{DCDC_W_51}{action}->(); print $pid{DCDC_W_51}{val} ."\n"; } sub U16 { my($a,$b)=@_; return ($a*256+$b); }

                "These opinions are my own, though for a small fee they be yours too."

Replies are listed 'Best First'.
Re^2: weird problem with macports perl on apple m1/m2 based system
by perltux (Monk) on Jun 10, 2023 at 21:49 UTC
    The evals are there because this test code is an extract of the larger program were I originally encountered the problem and there they are necessary (at least AFAIK), but the point isn't whether my code is optimized or not, the point is the weird behavior on the M1/M2 Macs, on all other systems I tested it on the code works fine and provides the expected correct result.
    If you are curious the original program is here: http://obd-amigos.linuxtech.net/files/