in reply to Re^4: Reading into array with sscanf
in thread Reading into array with sscanf

So what is the value in $c_speed[0] when update does not occur?

Perhaps you should try temporarily removing the validation check and see what gets displayed in the widget.

Replies are listed 'Best First'.
Re^6: Reading into array with sscanf
by colintu (Acolyte) on Jul 16, 2024 at 18:14 UTC

    If I do a print in the load subroutine I see the expected values from the file. But with the validation calls in the widget commented out and the actual validation subroutine also commented out the displayed value in the widget does NOT change when I do the load. even though I can use the mouse/keyboard to change it doing input to the widget. However, I've just discovered that although the *displayed* value in the Entry widget does *not* change when I do the load from file, the actual *variable* must have changed because the result of a calculation using it *does* change. Also even though I can use the mouse/keyboard to change the displayed value doing input to the widget, it isn't getting into the variable because the calculation result does not change. It's like doing the split alters the storage location of the variable array somehow and the widget doesn't get told.

      It's the -textvariable. You made a reference to an element of an array and then changed to an entirely different array. Don't do that. It's not the scanf, it's that you used

      ($c_speed[0], $c_speed[1], $c_speed[2], $c_speed[3]) = sscanf("%d %d % +d %d", $rstring);
      If you had used
      @c_speed = sscanf("%d %d %d %d", $rstring);
      it would have also failed.

      Try
      @c_speed[0 .. $#c_speed] = split ' ', <$rstring>;
      and report back. This should keep your -textvariable reference correct.


      Or not. You didn't provide a SSCCE so it's hard to tell...

        Thanks. That does indeed work. I think I understand your comment about "You made a reference to an element of an array and then changed to an entirely different array." I think I was creating a new list with a different array inside it. Can you point me to something that explains what your suggested code means? I don't recognise what "@c_speed0 .. $#c_speed" is doing. Unless the last bit is a reference to the last element or maybe the array size, which I think would tell split how many pieces I expect.