This module contains functions for parsing and doing substitutions in format strings similar to those used by printf. The %-escapes to be replaced can either be given using a hash, or, for maximum flexibility, using a callback function.

The first one, as described in the SYNOPSIS section, expects two arguments: A string that possibly contains escape sequences and a reference to a hash. The hash acts as a conversation table between valid escape sequences and replacement strings. In this mode, a default handler is used which is very close in behaviour to perl's builtin sprintf(). Here is another example:

The second method is more flexible. Instead of merely passing a conversation table, you can give a code reference to expand() that is used as a callback each time an escape sequence is detected in the string. Your handler is called with four or five arguments, depending on how you called expand():

flags: an arbitrary set of '-', '+', '0' and '#'

width: integer value

precision: integer value

format: a single letter

data: the data you passed to expand()

In case of error (such as an unexpected format character), your handler should return undef. That causes expand() to return undef as well.

Have a look at the default handler expand_handler of this module for an example.