Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Override printing to STDOUT/ERR

by bliako (Prior)
on Apr 13, 2018 at 13:56 UTC ( #1212809=note: print w/replies, xml ) Need Help??


in reply to Re: Override printing to STDOUT/ERR
in thread Override printing to STDOUT/ERR

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"); }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2020-10-25 05:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (249 votes). Check out past polls.

    Notices?