Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Appending time to each line

by ajose (Acolyte)
on May 21, 2013 at 10:35 UTC ( [id://1034499]=note: print w/replies, xml ) Need Help??


in reply to Re: Appending time to each line
in thread Appending time to each line

Thanks for the reply.. But how could I print date for Data::Dumper output in each line as shown in the example?

Replies are listed 'Best First'.
Re^3: Appending time to each line
by Corion (Patriarch) on May 21, 2013 at 10:58 UTC

    First capture the Data::Dumper output in a string, then prepend the timestamp:

    my $message= Dumper $myvar; $message=~ s!^!$timestamp !mg; print $message;
Re^3: Appending time to each line
by MidLifeXis (Monsignor) on May 21, 2013 at 13:05 UTC

    See the Data::Dumper $Data::Dumper::Pad configuration variable.

    --MidLifeXis

Re^3: Appending time to each line
by hdb (Monsignor) on May 21, 2013 at 13:49 UTC

    IMHO, it would make sense to encapsulate everything in a subroutine along the lines of

    use strict; use warnings; sub tprint { my $msg = join $,//'' ,@_; my $tstamp = localtime()." "; $msg =~ s/^/$tstamp/gm; print $msg; } tprint "something\nelse\n";

    BUT to completely replicate the interface of the print function is beyond my Perl skills. I have no idea how one could now provide a file handle to print into file.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-03-28 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found