I'm curious why I haven't see the following done, but I assume there is a reason.

Typically when using Carp or Devel::StackTrace, you get output like this:

at trace.pl line 28
    main::bar(3, 'ARRAY(0x100ae294)') called at trace.pl line 16
    main::foo(3) called at trace.pl line 11

You might very well want to know what's in that array, but you can't see it, even though it's trivial to display that information:

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; $Data::Dumper::Terse = 1; $Data::Dumper::Indent = 0; foo(3); sub foo { my $arg = shift; my @array = qw(this that); bar(3, \@array); } sub bar { my ($x, $y) = @_; my $level = 0; while ( my @caller = do { package DB; caller($level++) } ) { my $sub = $caller[3]; my $args = join ", " => map { Dumper($_) } @DB::args; print "$sub( $args )\n"; } }

That prints out:

main::bar(3, ['this','that'])
main::foo(3)

It would take a bit of massaging, but one could turn that into some very useful output. Of course, if you're passing around huge data structures or tied variables, there could be problems, but as a development tool, it could be quite useful. Is there a module which already does this? Debug::Trace looks really close, but it appears that you have to specify in advance what you want to trace and I just want to dump a stacktrace.

Cheers,
Ovid

New address of my CGI Course.


In reply to Stacktrace with variables filled in? by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.