The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

D'oh - Debug module that redirects STDOUT and STDERR

SYNOPSIS

	#!/usr/bin/perl
	use D'oh 'i_hate_this_program';
	D'oh::stderr('/tmp/stderr'); # redirect all stderr to /tmp/stderr

	# print date and script name/pid to STDERR
	D'oh::date();

	D'oh::stdout('/tmp/stdout'); # redirect all stderr to /tmp/stderr
	# print date and script name/pid to STDOUT
	D'oh::date('STDOUT');

    i_hate_this_program({ arbitrary => ['structured data'] });

	print "hellloooooo\n";
	die "world";

	__END__

    $ tail /tmp/stdout
    # D'oh: myscript [16440]: 2018-06-19 02:45:16.678Z
    hellloooooo

    $ tail /tmp/stderr
    # D'oh: myscript [16440]: 2018-06-19 02:45:16.677Z
    [{"arbitrary":["structured data"]}]
    world at myscript line 15.

DESCRIPTION

The module, when used, prints all STDERR or STDOUT to a given file, which is by default /tmp/D'oh.

stderr(FILENAME) and stdout(FILENAME) start the redirection. Redirection is not reversible (unless you save-and-restore the filehandles yourself). If no FILENAME is provided, the default is used.

date prints a timestamp to STDERR (date('STDOUT') prints it to STDOUT).

You can also dump random data as JSON to STDERR by calling any function name you want. Just import the name you want to use.

AUTHOR

Chris Nandor, pudge@pobox.com, http://pudge.net/

Copyright (c) 1998-2018 Chris Nandor. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

VERSION HISTORY

Version 1.00 (2018-06-18) Version 0.05 (1998-02-02)