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

Re^3: Module for Printing Line Numbers in Debug?

by LanX (Saint)
on Jan 21, 2013 at 13:35 UTC ( [id://1014445]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Module for Printing Line Numbers in Debug?
in thread Module for Printing Line Numbers in Debug?

I googled trace perl and found perl option to trace execution.

Devel::Trace seems to be what you are looking for.

EDIT: It's not clear for me if you wanna trace all lines or just some. In the latter case why not defining a function log() which carps what you want only if DEBUG is set?

Cheers Rolf

  • Comment on Re^3: Module for Printing Line Numbers in Debug?

Replies are listed 'Best First'.
Re^4: Module for Printing Line Numbers in Debug?
by QM (Parson) on Jan 21, 2013 at 14:19 UTC
    Devel::Trace might do it, but it's not installed on the system. Might be problematic to get it on there. (Ubuntu apt-get name?)

    I don't need to trace all the lines, but if that's necessary, I can live with it.

    I can already put a function or statement wherever I want, so a log() function would do the same, but would be a lot shorter than the literal statement. A good idea, I was hoping for something even cleaner, that won't show up in production code by mistake.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      > A good idea, I was hoping for something even cleaner, that won't show up in production code by mistake.

      It doesn't look like you will pass any arguments to log(), caller seems to provide anything you are looking for.

      If you later check for production environment and set

      sub log {}
      then it will be optimized and not appear in the opcodes.

      If you are still worried, use a name you can easily find and delete, like __LOG__, even a source filter doing this should be very safe.¹

      But please search the archives for older discussions, this is certainly not the first one.

      Cheers Rolf

      UPDATE

      ¹) or even better, use Damian's approach from Smart::Comments and use a source filter only in testing mode to enable log() by deleting the '#' with s/;#LOG/;LOG;/g

      s/a/b/ ;#LOG

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1014445]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-24 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found