[mh] eval'ing perl to create MH mqtt objects

Tom MacLean <[email protected]> Wed, 20 Oct 2021 23:13:26 -0400
Newsgroups gmane.comp.misc.misterhouse.user
Message-ID <[email protected]>

Hi All,

I apologize for being a hack .. despite using MH for almost 20 years, my perl knowledge is poor. 

I'm am trying to programatically make MQTT clones of specific MH objects by calculating a new name, a suitable MQTT topic name and then eval'ing the code to create the object and tie it to the original object:

This code is in a sub that receives the object I am linking to "mh_obj":
eval "$new_obj_name = new mqtt_Item(\$mqtt_1, \"$mqtt_topic\");";
eval "$mh_obj_name->tie_event('sync_mqtt($mh_obj_name, $new_obj_name,0)');";

The first line runs without errors (or visible result).  The second line runs successfully (because the event gets tied), but the $new_obj_name object isn't visible, I get 'Global symbol "$Basement_Landing_mqtt" (this is $new_obj_name) requires explicit package name'.  So the tied event code does not see the object I created in the first eval.
 
What went wrong?  Is my eval scope only that of the sub, and once the sub ends my created object dies?  Is there a way this can work?
 
Thanks,
Tom

________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users