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

PPrint - Programmable sprintf. Allows you to associate functions to directives and supplies fairly powerful default directives.

SYNOPSIS

  use PPrint;

  pprint("~2r", 8) => "1000"

DESCRIPTION

DIRECTIVES

PPrint provides a number of default directives.

R

~RADIX,MINCOL,PADCHAR,COMMAINTERVAL,COMMCHAR:;!R

Generic integer formating.

Parameters:

RADIX

Specifies the radix to use, values between 1 and 36 (inclusive) are allowed. Defaults to 10.

<MINCOL>

Minimum numbers of columns to use. Defaults to 0.

<PADCHAR>

If the length of the number is less than MINCOL extra PADCHAR chars will be added to the left of the string in order to make it MINCOL columns long. Defaults to '0'.

<COMMAINTERVAL>

Specifies how many chars should be between commas. Default is 3.

COMMACHAR

Specifies which character to use instead of ',' when splitting a large number. Default is ','.

Flags:

:

Seperate the number using COMMACHAR chars at intervals COMMAINTERVAL chars.

;

Always put the sign of the number. The effect of this flag is to add a '+' to positive numbers.

!

Add padding chars to the right instead of the left.

D

~MINCOL,PADCHAR,COMMAINTERVAL,COMMACHAR:;!D

Same as R directive with RADIX = 10.

O

~MINCOL,PADCHAR,COMMAINTERVAL,COMMACHAR:;!O

Same as R directive with RADIX = 8.

X

~MINCOL,PADCHAR,COMMAINTERVAL,COMMACHAR:;!X

Same as R directive with RADIX = 16.

B

~MINCOL,PADCHAR,COMMAINTERVAL,COMMACHAR:;!X

Same as R directive with RADIX = 2.

n

~REPEAT,TYPEn

Prints newlines.

Note that this directive consumes no elements from the arg list, unless 'v is used for REPEAT or TYPE of course.

Parameters:

REPEAT

Specifes how many newlines to write. Default is 1.

TYPE

Specifes which type of newline to write. 'u => unix (chr 0x0A), 'd => dos (chr(x0D) . chr(0x0A)), "m" => mac (chr 0x0D).

~

~REPEAT~

Prints tilde chars.

Parameter:

REPEAT

Speciifes the number of tilde chars to print. Default is 1.

S

~S

Printing strings, just like sprintf("%s", $arg);

A

~INDENT_STYLE,PURITY,USEQQ,TERSE,DEEPCOPY,QUOTEKEYS,MAXDEPTH A

Print with Data::Dumper. see the Data::Dumper man page for what the various options mean.

WRITING DIRECTIVES

One of the main reasons PPrint was written was to provide a way to customize how data should be printed, to this end PPrint can be extended to understand new directives.

FIXME: Describe it here. In the mean time look at the tilde and n directives.

CREDITS

Ideas liberally taken from Common Lisp's format directive.