See functions printi(), sprinti(), printp(), and sprintp(): you can also call them as method.
use String::Print 'oo'; my $f = String::Print->new(%config); $f->printi($format, @params);
# exactly the same functionality: use String::Print 'printi', %config; printi $format, @params;
The Object Oriented interface wins when you need the same configuration in multiple source files, or when you need different configurations within one program. In these cases, the hassle of explicitly using the object has some benefits.
Option | Default |
---|---|
encode_for | undef |
missing_key | <warning> |
modifiers |
|
serializers | <useful defaults> |
my $f = String::Print->new ( modifiers => [ EUR => sub {sprintf "%5.2f e", $_[0]} ] , serializers => [ UNDEF => sub {'-'} ] , encode_for => 'HTML' ); $f->printi("price: {p EUR}", p => 3.1415); # price: ␣␣3.14 e $f->printi("count: {c}", c => undef); # count: -
The PAIRS are a combination of an selector and a CODE which processes the
value when the modifier matches. The selector is a string or (preferred)
a regular expression. Later modifiers with the same name overrule earlier
definitions. You may also specify an ARRAY of modifiers per print
.
See section Interpolation: Modifiers about the details.
[0.91] Enable/define the output encoding. Read section Output encoding about the details.
The following are provided as method and as function. You find their explanation further down on this page.
$obj->printi([$fh], $format, PAIRS|HASH);
$obj->printp([$fh], $format, PAIRS|HASH);
$obj->sprinti($format, PAIRS|HASH);
$obj->sprintp($format, LIST, PAIRS);