Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Override printing to STDOUT/ERR

by bliako (Monsignor)
on Apr 13, 2018 at 13:56 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1212809]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-25 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found