Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
There's more than one way to do things
 
PerlMonks  

Detect variable change?

by DreamT (Monk)
on Apr 20, 2011 at 08:16 UTC ( #900289=perlquestion: print w/ replies, xml ) Need Help??
DreamT has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need to find out when a variable value is changed, when debugging a cgi script. I.e. I need to get a log post saying "$my_variable changed value to "abc123" at line xyz".

I guess this is done in some kind of debug/trace manner?
Is it possible?

Comment on Detect variable change?
Re: Detect variable change?
by believer (Sexton) on Apr 20, 2011 at 08:30 UTC
Re: Detect variable change?
by tospo (Hermit) on Apr 20, 2011 at 08:38 UTC
    You could achieve this with the Perl debugger. The trick is to get an interactive debugger session into your CGI script as you interact with it through a web page. I do this with Catalyst apps and it fires of a terminal on my system when the code encounters a "$DB::single=1;" line. I'm not sure exactly how to acheive this with a simple CGI script but this thread here Debugging CGI/PERL has some advice on that.
    Once you have the debugger session you can monitor a variable by setting a watch expression (w NAME_OF_VARIABLE), which will be triggered whenever the value of the variable changes.
      IIRC Devel::ptkdb can be used for CGIs:

      ... from the docs

      PTKDB_DISPLAY
      Sets the X display that the ptkdb window will appear on when invoked. Useful for debugging CGI scripts on remote systems.

      Cheers Rolf

      UPDATE: see Re: Debugging CGI/PERL

Re: Detect variable change?
by Fletch (Chancellor) on Apr 20, 2011 at 13:15 UTC

    Smart::Comments and Devel::Trace may also be of interest. With the former you'd just use it and add a comment like ### $my_variable where you want to see its value (and the nice thing is you just comment out the use Smart::Comments line and it becomes just a plain old inert comment that doesn't affect your program or its output).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Detect variable change?
by toolic (Chancellor) on Apr 20, 2011 at 13:20 UTC
    Devel::DumpTrace
    "will cause a message to be printed to standard error for each line of source code that is executed. In addition, this module will attempt to identify variable names in the source code and substitute the values of those variables."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://900289]
Approved by Corion
Front-paged by DrHyde
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-04-21 05:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (490 votes), past polls