thanks for the recommendation. Following your suggestion I stumbled upon Tie::STDOUT (by David Cantrell) which does the trick:
#!/usr/bin/env perl
use strict;
use warnings;
use Tie::STDOUT
print => sub {
my @params = @_;
my @calhis = ();
my $i = 2; # to avoid printing stacktrace for Tie::STDOUT
# build a kind of stacktrace:
while(
my ($package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask,
$hinthash) = caller($i++)
){
push(@calhis, "$filename, line $line : $package".'::'."$subrou
+tine");
}
# print the stacktrace with whatever needs to be printed
print join("->", @calhis), " : ", @_;
}
;
print "from main\n";
sub1("main");
sub2("main");
sub sub1 {
my $via = $_[0];
print "from sub1 via $via\n";
}
sub sub2 {
sub1("sub2");
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.