Re: [mh] Problem with timer variable

Paul Onley <[email protected]>
Newsgroups gmane.comp.misc.misterhouse.user
Message-ID <[email protected]>
On 12/04/2018 03:25 PM, Jeff Siddall wrote:

> On 11/27/18 3:56 PM, Paul Onley wrote:
>> I am by no means an expert in perl but I have managed to get by OK 
>> with mh for about 20 years. I only use a small portion of 
>> misterhouses capabillities but I vary much appreciate it's incredible 
>> flexibility.
>>
>> I'm having a problem with some code I have written that I do not 
>> understand.
>>
>> In my code I have a hash of motion sensors which points to hashes of 
>> each room, I would like to use:
>>
>>      set $MotionSensors{$SensorID}{timer} 
>> $MotionSensors{$SensorID}{occupied_time}, 
>> $MotionSensors{$SensorID}{timer_cmd};
>>
>> but get the error:
>>    11/26/18 09:52:10 PM: syntax error at (eval 1086) line 4695, near 
>> "$MyMotionSen{"
>> Global symbol "$benchmark_tickcount" requires explicit package name 
>> at (eval 1086) line 4723.
>> Global symbol "$benchmark_tickcount" requires explicit package name 
>> at (eval 1086) line 4723.
>> syntax error at (eval 1086) line 4725, near ";
>> syntax error at (eval 1086) line 4746, near ";
>> syntax error at (eval 1086) line 4767, near ";
>> BEGIN not safe after errors--compilation aborted at (eval 1086) line 
>> 4778.
>>          main::__ANON__('syntax error at (eval 1086) line 4695, near 
>> "$MyMotionSen{"\x{a}G...') called at (eval 1086) line 4778
>
> Hard to know for sure but it appears there is something strange in one 
> of your variables -- presumably $SensorID.  Have a look at this:
>
> syntax error at (eval 1086) line 4695, near "$MyMotionSen{"\x{a}G...
> ----------------------------------------------------------^
>
> It looks to me like that scalar is somehow being set to something 
> strange.
>
> I would recommend temporarily commenting all the code that uses 
> $SensorID and instead just print $SensorID so you can find out what it 
> contains.
>
> Once you know what it contains try just one line of your code and see 
> if you can get that to work.  Once you have that working add the rest 
> of your code until you get it working or find the real issue.
>
> Jeff
>
>
> ________________________________________________________
> To unsubscribe from this list, go to: 
> https://lists.sourceforge.net/lists/listinfo/misterhouse-users
>
>
Thanks for the reply Jeff, my full code uses $SensorID in a number of 
places and this is the only line that has a problem. The thing that has 
me confused is that I cannot feed the hash element to set but if I set a 
scalar set to the hash value I can send that to set with no problem. The 
error is thrown at startup like timer.pm does not like the hash value, 
as I posted

     $timer            = $MotionSensors{$SensorID}{timer};
         set $timer $MotionSensors{$SensorID}{occupied_time}, 
$MotionSensors{$SensorID}{timer_cmd};


works fine but

     set $MotionSensors{$SensorID}{timer} 
$MotionSensors{$SensorID}{occupied_time}, 
$MotionSensors{$SensorID}{timer_cmd};


throws the error. Note that $SensorID is used in the code that works for 
the time and command portions of timer.pm set method but not for the 
timer itself. I have added code to print both $timer and 
$MotionSensors{$SensorID}{timer} and they both print the same timer hash 
information. Before posting I wrote the following code to see just what 
was happening and I have posted the output of the code which 
demonstrates that the set method can use the hash{}{} and $SensorID is 
OK. As you can see I pulled seconds_remaining 3 different ways and they 
all worked even the ones using $MotionSensors{$SensorID}{timer} I just 
do not understand what the difference is between using the hash{}{} 
syntax and the scalar=hash{}{} with the set method, of course there is a 
lot I don't completely understand about perl.

      my $timeshort = seconds_remaining $timer;
      my $time      = $MotionSensors{$SensorID}{timer}->seconds_remaining;

     print BRIGHT_YELLOW,
"\$timer ---  $timer  $timeshort  ## \$MotionSensors{\$SensorID}{timer} 
--- $MotionSensors{$SensorID}{timer}  $time  " . 
$MotionSensors{$SensorID}{timer}->seconds_remaining . "\n",
     RESET;


OUTPUT:

$timer ---  Timer=HASH(0x217dd78)  3579.0  ## 
$MotionSensors{$SensorID}{timer} --- Timer=HASH(0x217dd78)  3579.0 3579.0


Thanks again
Paul

________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.