CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Wanting to debug live code by using a "bypass"?

 



srhadden
Novice

Dec 28, 2011, 4:06 PM

Post #1 of 5 (1420 views)
Wanting to debug live code by using a "bypass"? Can't Post

I have some code that is in production. There isn't a test environment for this code. So I would like to be able to modify it without risk to the development team.

So I've thought about this idea.

program.pl is the file that our engineering team uses.

I must enter program.pl, becaues it is called by something else that I can't change. I want to debug/work on program.pl.

I thought maybe I could take program.pl and copy it to my_program.pl.

Then at the top of program.pl, do some kind of magic that will execute my_program.pl code if an environment variable is set. Otherwise, it just executes the code that already exists in program.pl.

All I would need to do is add a few lines at the top of program.pl, very low risk.

So I'm looking for options. I thought there was a command that would let perl take in a string of perl code and then execute it, but I don't know if seeing the same sub-routines defined twice in a perl file would cause a problem, most likely.

Or maybe the simple solution is to just put a condition, and execute my second perl script, passing all the arguments to it, and then exiting if an environment variable is set.

Thank you for any ideas.


rovf
Veteran

Dec 29, 2011, 5:55 AM

Post #2 of 5 (1390 views)
Re: [srhadden] Wanting to debug live code by using a "bypass"? [In reply to] Can't Post

If you want to do the decision based on an environment variable, you could write the following at the first line in program.pl:


Code
use Config; 
BEGIN {
if($ENV{MY_MAGIC_VAR}//q()) {
exec($Config{perlpath},$ENV{MY_MAGIC_VAR},@ARGV) or die "exec failed ($!)";
}
}


Hence, by setting MY_MAGIC_VAR to the path of your my_program.pl, this would be executed.


srhadden
Novice

Dec 29, 2011, 3:20 PM

Post #3 of 5 (1360 views)
Re: [rovf] Wanting to debug live code by using a "bypass"? [In reply to] Can't Post

Thanks, I wish I could say I knew what some of that meant :).



//q(), and $Config{perlpath} just returns "perl", nothing else. Is there something important about some of those extra pieces? Thanks again.


rovf
Veteran

Dec 29, 2011, 10:18 PM

Post #4 of 5 (1352 views)
Re: [srhadden] Wanting to debug live code by using a "bypass"? [In reply to] Can't Post

// is an operator introduced with Perl 5.10. It returns its right operand if its left operand is undef.

q() is just a different way to write single quotes, i.e. q(abc) is the same as 'abc'. I sometimes prefer q(), in particular in forums where proportional font is used, because two single quotes '' are sometimes misread as one double quotes ", so the q() notation is clearer.

$Config{perlpath} is supposed to return the path to that Perl installation which was used to invoke your Perl program (since you might have several Perl on your machine). That way, it ensures that your my_program.pl will be executed with the same Perl. I'm surprised that you don't get the whole Path to your Perl. Not important in this context, but maybe interesting to find out, why this is the case.


srhadden
Novice

Dec 30, 2011, 1:30 PM

Post #5 of 5 (1338 views)
Re: [rovf] Wanting to debug live code by using a "bypass"? [In reply to] Can't Post

Thanks! We've been stuck with 5.8 for a looong time, so probably why I haven't see the // used.



Thank you!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives