Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Detect variable change?

by DreamT (Pilgrim)
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?

Replies are listed 'Best First'.
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

      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 toolic (Bishop) on Apr 20, 2011 at 13:20 UTC
    "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."
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://900289]
Approved by Corion
Front-paged by DrHyde
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2018-05-26 22:37 GMT
Find Nodes?
    Voting Booth?