The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

P, Pe, Pa, Pae Safer, General Format + Print sub

VERSION

Version "1.0.10"

SYNOPSIS

P <FILEHANDLE, FORMAT, LIST|FORMAT, LIST|LIST >
Pa @ARRAY
Pe, Pae (same as P and Pa but ouput defaults to STDERR)

Combined printf, sprintf & say in 1 routine (almost). Can safely handle *args* to formmatted strings that are 'undef' & will print '(undef)' in place of the output. It knows how to print simple references and does so automatically rather than HASH=(0x235432), at the 1st level, it will print the contents of the hash: {none=>0, one=>1, two=>2}. Meant for use in development and as debug aid. Made executable and run, it does a small self-demo/test. Pod-documentation also builtin.

DESCRIPTION

While designed to speed up and simplify development, isn't limited to such.

It tries to auto-handle adding Newlines at the end of a line, substrating or adding LF's at the end depending on the circumstance. When you print vars via a string format, "undef" is handled 'in-line', with (undef) being printed in fields (though it is likely to retrn a 0 for numeric formats at this time.

The auto-newline feature at the end of a line can be supressed by adding the Unicode control char "Don't break here" (0x83) at the end of a string.

Any items printed as strings that are undef -- will print '(undef)'.

EXAMPLES

P "Hello %s", "World"; # auto NL when to a FH
P "Hello \x83"; P "World"; # \x83: suppress auto-NL to FH's
$s = P "%s", "Hello %s"; # not needed if printing to string
P $s, "World"; # still prints "Hello World"
@a = ("%s", "my string"); # using array, fmt as 1st arg
Pa @a; # use 'Pa' have @a as args to 'P'
@a = ("Hello %s", "World"); # format in array[0]
Pa @a; # use @a as args for P
P @a; # prints first of @a elements (Hello %s)
P 0 + @a; # prints #items in 'a'
P "a=%s", \@a; # prints contents of 'a': [1,2,3...]
P STDERR, @a # use @a as args to a specific FH
# NOTE: "," after FH "*STC"
Pe "Output to STDERR" # 'Shortcut' for P to STDERR
# P Hash bucket usage + contents with hashes
%H=(one=>1, two=>2, u=>undef);
P "%H #items %s", 0+%H; # - Show number of items in hash
P "%H hash usage: %s", "".%H; # - Shows used/total Hash bucket usage
P "%H=%s", \%H; # show contents of hash {x=>y, ...}
P "*this=%s", $this; # show blessed objs. + top-lvl content

NOTES

Note, values given as args to a formatted print statement, are checked for undef and substitute "(undef)" for undefined values. If you print vars as numbers, this can have the side effect of causing runtime format errors, so best to print as strings to see 'undef'. While usable in any code, it's use was designed to save typing, time and work of undef checking, newline handling, and doing the right thing with given input. It may not be suitable where speed is important.