From: Michelle D. <md...@oc...> - 2012-08-30 14:36:13
|
I'm having trouble calling a subroutine in one code file from another file. I'm new to perl but making my way through it! In one code file I have code which fires when a garage door is opened: print_log "Weeder: Garage open detected."; &garage_lights_onopen(); In a seperate code file I have my subroutine: sub garage_lights_onopen { print("Garage Lights: Garage open triggering lights on"); set $Garage_Lights_Timer 600; $Garage_Inside_Light->set('on'); } Can someone explain why this isn't working? I see the first print_log message when my garage door is opened, but never the second print_log, and no errors in the logs/screen. Is this a Perl/MH thing that I don't understand? Thanks! |
From: Eloy P. <pe...@ch...> - 2012-08-30 14:43:28
|
Hi Michelle, On 08/30/2012 10:35 AM, Michelle Dupuis wrote: > I'm having trouble calling a subroutine in one code file from another > file. I'm new to perl but making my way through it! > In one code file I have code which fires when a garage door is opened: > print_log "Weeder: Garage open detected."; > &garage_lights_onopen(); > In a seperate code file I have my subroutine: > sub garage_lights_onopen { > print("Garage Lights: Garage open triggering lights on"); > set $Garage_Lights_Timer 600; > $Garage_Inside_Light->set('on'); > } > Can someone explain why this isn't working? I see the first print_log > message when my garage door is opened, but never the second print_log, > and no errors in the logs/screen. Is this a Perl/MH thing that I don't > understand? The second is not a print_log(); it's a print(). Output of that print statement will go to standard output because no file descriptor is being used for the print() statement (as in "print FILE ..."). You should be able to see standard output on the terminal where MH is running. Is that not the case? If so, do you have standard output redirected to a file? Easiest solution is to make that print() a print_log(). Is the garage light turning on? If so that the proof that garage_lights_onopen() is running. Cheers, Eloy Paris.- |
From: Michelle D. <md...@oc...> - 2012-08-30 15:11:23
|
I changed the print to print_log but the problem is the same. I see the first message on screen (weeder sensed the open), but not the second message (that the light will turn on). And the light doesn't turn on either... It's as if the subroutine is never called. Thanks ________________________________________ From: Eloy Paris [pe...@ch...] Sent: Thursday, August 30, 2012 10:43 AM To: mis...@li... Subject: Re: [mh] calling sub in another file (perl question) Hi Michelle, On 08/30/2012 10:35 AM, Michelle Dupuis wrote: > I'm having trouble calling a subroutine in one code file from another > file. I'm new to perl but making my way through it! > In one code file I have code which fires when a garage door is opened: > print_log "Weeder: Garage open detected."; > &garage_lights_onopen(); > In a seperate code file I have my subroutine: > sub garage_lights_onopen { > print("Garage Lights: Garage open triggering lights on"); > set $Garage_Lights_Timer 600; > $Garage_Inside_Light->set('on'); > } > Can someone explain why this isn't working? I see the first print_log > message when my garage door is opened, but never the second print_log, > and no errors in the logs/screen. Is this a Perl/MH thing that I don't > understand? The second is not a print_log(); it's a print(). Output of that print statement will go to standard output because no file descriptor is being used for the print() statement (as in "print FILE ..."). You should be able to see standard output on the terminal where MH is running. Is that not the case? If so, do you have standard output redirected to a file? Easiest solution is to make that print() a print_log(). Is the garage light turning on? If so that the proof that garage_lights_onopen() is running. Cheers, Eloy Paris.- ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ________________________________________________________ To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365 |
From: Alan W. <arw...@we...> - 2012-09-03 13:55:46
|
Not a solution to your problem, but shouldn't there be a return at the end of your subroutine to return the value you will discard? You could also put in a print_log for the &garage_onopen subroutine to print a value. Personally when chasing problems like this I put a couple print_logs around the offending statement so I know it gets TO the statements and then figure out why it didn't go off. Is there anything in the error log or the print log about not finding the subroutine? On Thu, Aug 30, 2012 at 8:09 AM, Michelle Dupuis <md...@oc...> wrote: > I changed the print to print_log but the problem is the same. I see the first message on screen (weeder sensed the open), but not the second message (that the light will turn on). And the light doesn't turn on either... > > It's as if the subroutine is never called. > > Thanks > > ________________________________________ > From: Eloy Paris [pe...@ch...] > Sent: Thursday, August 30, 2012 10:43 AM > To: mis...@li... > Subject: Re: [mh] calling sub in another file (perl question) > > Hi Michelle, > > On 08/30/2012 10:35 AM, Michelle Dupuis wrote: > >> I'm having trouble calling a subroutine in one code file from another >> file. I'm new to perl but making my way through it! >> In one code file I have code which fires when a garage door is opened: >> print_log "Weeder: Garage open detected."; >> &garage_lights_onopen(); >> In a seperate code file I have my subroutine: >> sub garage_lights_onopen { >> print("Garage Lights: Garage open triggering lights on"); >> set $Garage_Lights_Timer 600; >> $Garage_Inside_Light->set('on'); >> } >> Can someone explain why this isn't working? I see the first print_log >> message when my garage door is opened, but never the second print_log, >> and no errors in the logs/screen. Is this a Perl/MH thing that I don't >> understand? > > The second is not a print_log(); it's a print(). Output of that print > statement will go to standard output because no file descriptor is being > used for the print() statement (as in "print FILE ..."). > > You should be able to see standard output on the terminal where MH is > running. Is that not the case? If so, do you have standard output > redirected to a file? > > Easiest solution is to make that print() a print_log(). > > Is the garage light turning on? If so that the proof that > garage_lights_onopen() is running. > > Cheers, > > Eloy Paris.- > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > ________________________________________________________ > To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365 > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > ________________________________________________________ > To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365 > |
From: Michelle D. <md...@oc...> - 2012-09-13 21:32:00
|
Well, I retyped the file from scratch. I did a test with a small file and it worked properly, so something in that file was a problem. Now working Thanks! ________________________________________ From: Alan Womack [arw...@we...] Sent: Monday, September 03, 2012 9:55 AM To: The main list for the MisterHouse home automation program Subject: Re: [mh] calling sub in another file (perl question) Not a solution to your problem, but shouldn't there be a return at the end of your subroutine to return the value you will discard? You could also put in a print_log for the &garage_onopen subroutine to print a value. Personally when chasing problems like this I put a couple print_logs around the offending statement so I know it gets TO the statements and then figure out why it didn't go off. Is there anything in the error log or the print log about not finding the subroutine? On Thu, Aug 30, 2012 at 8:09 AM, Michelle Dupuis <md...@oc...> wrote: > I changed the print to print_log but the problem is the same. I see the first message on screen (weeder sensed the open), but not the second message (that the light will turn on). And the light doesn't turn on either... > > It's as if the subroutine is never called. > > Thanks > > ________________________________________ > From: Eloy Paris [pe...@ch...] > Sent: Thursday, August 30, 2012 10:43 AM > To: mis...@li... > Subject: Re: [mh] calling sub in another file (perl question) > > Hi Michelle, > > On 08/30/2012 10:35 AM, Michelle Dupuis wrote: > >> I'm having trouble calling a subroutine in one code file from another >> file. I'm new to perl but making my way through it! >> In one code file I have code which fires when a garage door is opened: >> print_log "Weeder: Garage open detected."; >> &garage_lights_onopen(); >> In a seperate code file I have my subroutine: >> sub garage_lights_onopen { >> print("Garage Lights: Garage open triggering lights on"); >> set $Garage_Lights_Timer 600; >> $Garage_Inside_Light->set('on'); >> } >> Can someone explain why this isn't working? I see the first print_log >> message when my garage door is opened, but never the second print_log, >> and no errors in the logs/screen. Is this a Perl/MH thing that I don't >> understand? > > The second is not a print_log(); it's a print(). Output of that print > statement will go to standard output because no file descriptor is being > used for the print() statement (as in "print FILE ..."). > > You should be able to see standard output on the terminal where MH is > running. Is that not the case? If so, do you have standard output > redirected to a file? > > Easiest solution is to make that print() a print_log(). > > Is the garage light turning on? If so that the proof that > garage_lights_onopen() is running. > > Cheers, > > Eloy Paris.- > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > ________________________________________________________ > To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365 > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > ________________________________________________________ > To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365 > ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ________________________________________________________ To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365 |
From: Ron B. <rb...@be...> - 2012-09-03 16:02:26
|
On 08/30/2012 10:35 AM, Michelle Dupuis wrote: > I'm having trouble calling a subroutine in one code file from another > file. I'm new to perl but making my way through it! > In one code file I have code which fires when a garage door is opened: > print_log "Weeder: Garage open detected."; > &garage_lights_onopen(); > In a seperate code file I have my subroutine: > sub garage_lights_onopen { > print("Garage Lights: Garage open triggering lights on"); > set $Garage_Lights_Timer 600; > $Garage_Inside_Light->set('on'); > } > Can someone explain why this isn't working? I see the first print_log > message when my garage door is opened, but never the second print_log, > and no errors in the logs/screen. Is this a Perl/MH thing that I don't > understand? try this: for example purposes we will call your first code file file1.pl and your second code file file2.pl your first code file (file1.pl) contains: unshift(@INC, "path_to_where_your_file2.pl_is_located"); require "file2.pl";# tells file1.pl where to find the subroutine print_log "Weeder: Garage open detected."; &garage_lights_onopen(); your second code file (file2.pl) should look like this (pay attention to the "trailing 1"): sub garage_lights_onopen { print("Garage Lights: Garage open triggering lights on"); set $Garage_Lights_Timer 600; $Garage_Inside_Light->set('on'); } 1; # this is a numeric one and is absolutely required --------------- In my opinion the best Perl book written is "Perl by Example" by Ellie Quigley. Price ~$50.00. Its worth every penny and you owe it to yourself. Make sure you get the latest edition/priting. hope this helps Ron > Thanks! > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > > > > ________________________________________________________ > To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365 > |
From: Ron B. <rb...@be...> - 2012-09-03 16:59:50
|
On 09/03/2012 12:02 PM, Ron Blout wrote: > On 08/30/2012 10:35 AM, Michelle Dupuis wrote: >> I'm having trouble calling a subroutine in one code file from another >> file. I'm new to perl but making my way through it! >> In one code file I have code which fires when a garage door is opened: >> print_log "Weeder: Garage open detected."; >> &garage_lights_onopen(); >> In a seperate code file I have my subroutine: >> sub garage_lights_onopen { >> print("Garage Lights: Garage open triggering lights on"); >> set $Garage_Lights_Timer 600; >> $Garage_Inside_Light->set('on'); >> } >> Can someone explain why this isn't working? I see the first print_log >> message when my garage door is opened, but never the second print_log, >> and no errors in the logs/screen. Is this a Perl/MH thing that I don't >> understand? > > try this: > for example purposes we will call your first code file file1.pl and your > second code file file2.pl pay attention to the double quotes in the example below. they are necessary. > > your first code file (file1.pl) contains: > > unshift(@INC, "path_to_where_your_file2.pl_is_located"); > require "file2.pl";# tells file1.pl where to find the subroutine > > print_log "Weeder: Garage open detected."; > &garage_lights_onopen(); > > > your second code file (file2.pl) should look like this (pay attention to > the "trailing 1"): > > sub garage_lights_onopen { > print("Garage Lights: Garage open triggering lights on"); > set $Garage_Lights_Timer 600; > $Garage_Inside_Light->set('on'); > } > 1; # this is a numeric one and is absolutely required > > --------------- > > In my opinion the best Perl book written is "Perl by Example" by Ellie > Quigley. Price ~$50.00. Its worth every penny and you owe it to > yourself. Make sure you get the latest edition/priting. > > hope this helps > > Ron > >> Thanks! >> >> >> ------------------------------------------------------------------------------ >> Live Security Virtual Conference >> Exclusive live event will cover all the ways today's security and >> threat landscape has changed and how IT managers can respond. Discussions >> will include endpoint security, mobile security and the latest in malware >> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >> >> >> >> ________________________________________________________ >> To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365 >> > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > ________________________________________________________ > To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365 > > |
From: Alan W. <arw...@we...> - 2012-09-03 17:23:59
|
Thanks for the tip on the book, picked it up for the Kindle for $18.00. That way I can reference it from the laptop, the phone, the desktop, or the tablet! In my opinion the best Perl book written is "Perl by Example" by Ellie > Quigley. Price ~$50.00. Its worth every penny and you owe it to > yourself. Make sure you get the latest edition/priting. > > hope this helps > > Ron |
From: Ron B. <rb...@be...> - 2012-09-03 19:32:14
|
On 09/03/2012 01:23 PM, Alan Womack wrote: > Thanks for the tip on the book, picked it up for the Kindle for > $18.00. That way I can reference it from the laptop, the phone, the > desktop, or the tablet! I have the 3rd edition and found it to be most valuable. I believe the latest edition is the 4th edition. I was a bit high on the price and had not considered an electronic copy. Amazon is listing the paperback at around $30.00. Still a bargain. > > In my opinion the best Perl book written is "Perl by Example" by Ellie >> Quigley. Price ~$50.00. Its worth every penny and you owe it to >> yourself. Make sure you get the latest edition/priting. >> >> hope this helps >> >> Ron > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > ________________________________________________________ > To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365 > > |