Linda A Walsh > P-1.0.9 > P

Download:
P-1.0.9.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 1.0.9   Source   Latest Release: P-1.1.24

NAME ^

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

VERSION ^

Version "1.0.9"

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 with development in mind, isn't limited to such.

It combines features of printf, sprintf, and say: printing to strings if its output is assign to something, adding newlines when output is not to a string, ignoring a single extra newlines if added, allowing suppression of the auto-newline using the Unicode-control char "\0x83" "Don't break here".

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 has 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. Hidden (but documented) feature: inserting the 'NO BREAK HERE' control- char (\x83) as the last char of a string will suppress a 'break' (newline) where it normally would be added.

syntax highlighting: