{
    "mode": "perldoc",
    "parameter": "Text::Reform",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Text%3A%3AReform/json",
    "generated": "2026-06-11T10:48:42Z",
    "synopsis": "use Text::Reform;\nprint form $template,\n$data, $to, $fill, $it, $with;\nuse Text::Reform qw( tag );\nprint tag 'B', $enboldenedtext;",
    "sections": {
        "NAME": {
            "content": "Text::Reform - Manual text wrapping and reformatting\n",
            "subsections": []
        },
        "VERSION": {
            "content": "This document describes version 1.20 of Text::Reform, released 2009-09-06.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Text::Reform;\n\nprint form $template,\n$data, $to, $fill, $it, $with;\n\n\nuse Text::Reform qw( tag );\n\nprint tag 'B', $enboldenedtext;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The \"form\" sub\nThe \"form()\" subroutine may be exported from the module. It takes a series of format (or\n\"picture\") strings followed by replacement values, interpolates those values into each picture\nstring, and returns the result. The effect is similar to the inbuilt perl \"format\" mechanism,\nalthough the field specification syntax is simpler and some of the formatting behaviour is more\nsophisticated.\n\nA picture string consists of sequences of the following characters:\n\n<       Left-justified field indicator. A series of two or more sequential <'s specify a\nleft-justified field to be filled by a subsequent value. A single < is formatted as the\nliteral character '<'\n\n>       Right-justified field indicator. A series of two or more sequential >'s specify a\nright-justified field to be filled by a subsequent value. A single > is formatted as the\nliteral character '>'\n\n<<<>>>  Fully-justified field indicator. Field may be of any width, and brackets need not\nbalance, but there must be at least 2 '<' and 2 '>'.\n\n^       Centre-justified field indicator. A series of two or more sequential ^'s specify a\ncentred field to be filled by a subsequent value. A single ^ is formatted as the literal\ncharacter '^'\n\n>>>.<<<<\nA numerically formatted field with the specified number of digits to either side of the\ndecimal place. See \"Numerical formatting\" below.\n\n[       Left-justified block field indicator. Just like a < field, except it repeats as required\non subsequent lines. See below. A single [ is formatted as the literal character '['\n\n]       Right-justified block field indicator. Just like a > field, except it repeats as\nrequired on subsequent lines. See below. A single ] is formatted as the literal\ncharacter ']'\n\n[[[]]]  Fully-justified block field indicator. Just like a <<<>>> field, except it repeats as\nrequired on subsequent lines. See below. Field may be of any width, and brackets need\nnot balance, but there must be at least 2 '[' and 2 ']'.\n\n|       Centre-justified block field indicator. Just like a ^ field, except it repeats as\nrequired on subsequent lines. See below. A single | is formatted as the literal\ncharacter '|'\n\n]]].[[[[\nA numerically formatted block field with the specified number of digits to either side\nof the decimal place. Just like a >>>.<<<< field, except it repeats as required on\nsubsequent lines. See below.\n\n~       A one-character wide block field.\n\n\\       Literal escape of next character (e.g. \"\\~\" is formatted as '~', not a one character\nwide block field).\n\nAny other character\nThat literal character.\n\nAny substitution value which is \"undef\" (either explicitly so, or because it is missing) is\nreplaced by an empty string.\n",
            "subsections": [
                {
                    "name": "Controlling line filling.",
                    "content": "Note that, unlike the a perl \"format\", \"form\" preserves whitespace (including newlines) unless\ncalled with certain options.\n\nThe \"squeeze\" option (when specified with a true value) causes any sequence of spaces and/or\ntabs (but not newlines) in an interpolated string to be replaced with a single space.\n\nA true value for the \"fill\" option causes (only) newlines to be squeezed.\n\nTo minimize all whitespace, you need to specify both options. Hence:\n\n$format = \"EG> [[[[[[[[[[[[[[[[[[[[[\";\n$data   = \"h  e\\t l lo\\nworld\\t\\t\\t\\t\\t\";\n\nprint form $format, $data;              # all whitespace preserved:\n#\n# EG> h  e            l lo\n# EG> world\n\n\nprint form {squeeze=>1},                # only newlines preserved:\n$format, $data;              #\n# EG> h e l lo\n# EG> world\n\n\nprint form {fill=>1},                   # only spaces/tabs preserved:\n$format, $data;             #\n# EG> h  e        l lo world\n\n\nprint form {squeeze=>1, fill=>1},       # no whitespace preserved:\n$format, $data;              #\n# EG> h e l lo world\n\nWhether or not filling or squeezing is in effect, \"form\" can also be directed to trim any extra\nwhitespace from the end of each line it formats, using the \"trim\" option. If this option is\nspecified with a true value, every line returned by \"form\" will automatically have the\nsubstitution \"s/[ \\t]+$//gm\" applied to it.\n\nHence:\n\nprint length form \"[[[[[[[[[[\", \"short\";\n# 11\n\nprint length form {trim=>1}, \"[[[[[[[[[[\", \"short\";\n# 6\n\nIt is also possible to control the character used to fill lines that are too short, using the\n'filler' option. If this option is specified the value of the 'filler' flag is used as the fill\nstring, rather than the default \" \".\n\nFor example:\n\nprint form { filler=>'*' },\n\"Pay bearer: ^^^^^^^^^^^^^^^^^^^\",\n'$123.45';\n\nprints:\n\nPay bearer: $123.45\n\nIf the filler string is longer than one character, it is truncated to the appropriate length.\nSo:\n\nprint form { filler=>'-->' },\n\"Pay bearer: ]]]]]]]]]]]]]]]]]]]\",\n['$1234.50', '$123.45', '$12.34'];\n\nprints:\n\nPay bearer: ->-->-->-->$1234.50\nPay bearer: -->-->-->-->$123.45\nPay bearer: >-->-->-->-->$12.34\n\nIf the value of the 'filler' option is a hash, then it's 'left' and 'right' entries specify\nseparate filler strings for each side of an interpolated value. So:\n\nprint form { filler=>{left=>'->', right=>'*'} },\n\"Pay bearer: <<<<<<<<<<<<<<<<<<\",\n'$123.45',\n\"Pay bearer: >>>>>>>>>>>>>>>>>>\",\n'$123.45',\n\"Pay bearer: ^^^^^^^^^^^^^^^^^^\",\n'$123.45';\n\nprints:\n\nPay bearer: $123.45*\nPay bearer: >->->->->->$123.45\nPay bearer: >->->$123.45\n"
                },
                {
                    "name": "Temporary and permanent default options",
                    "content": "If \"form\" is called with options, but no template string or data, it resets it's defaults to the\noptions specified. If called in a void context:\n\nform { squeeze => 1, trim => 1 };\n\nthe options become permanent defaults.\n\nHowever, when called with only options in non-void context, \"form\" resets its defaults to those\noptions and returns an object. The reset default values persist only until that returned object\nis destroyed. Hence to temporarily reset \"form\"'s defaults within a single subroutine:\n\nsub single {\nmy $tmp = form { squeeze => 1, trim => 1 };\n\n# do formatting with the obove defaults\n\n} # form's defaults revert to previous values as $tmp object destroyed\n"
                },
                {
                    "name": "Multi-line format specifiers and interleaving",
                    "content": "By default, if a format specifier contains two or more lines (i.e. one or more newline\ncharacters), the entire format specifier is repeatedly filled as a unit, until all block fields\nhave consumed their corresponding arguments. For example, to build a simple look-up table:\n\nmy @values   = (1..12);\n\nmy @squares  = map { sprintf \"%.6g\", $2    } @values;\nmy @roots    = map { sprintf \"%.6g\", sqrt($) } @values;\nmy @logs     = map { sprintf \"%.6g\", log($)  } @values;\nmy @inverses = map { sprintf \"%.6g\", 1/$     } @values;\n\nprint form\n\"  N      N2    sqrt(N)      log(N)      1/N\",\n\"=====================================================\",\n\"| [[  |  [[[  |  [[[[[[[[[[ | [[[[[[[[[ | [[[[[[[[[ |\n-----------------------------------------------------\",\n\\@values, \\@squares, \\@roots, \\@logs, \\@inverses;\n\nThe multiline format specifier:\n\n\"| [[  |  [[[  |  [[[[[[[[[[ | [[[[[[[[[ | [[[[[[[[[ |\n-----------------------------------------------------\",\n\nis treated as a single logical line. So \"form\" alternately fills the first physical line\n(interpolating one value from each of the arrays) and the second physical line (which puts a\nline of dashes between each row of the table) producing:\n\nN      N2    sqrt(N)      log(N)      1/N\n=====================================================\n| 1   |  1    |  1          | 0         | 1         |\n-----------------------------------------------------\n| 2   |  4    |  1.41421    | 0.693147  | 0.5       |\n-----------------------------------------------------\n| 3   |  9    |  1.73205    | 1.09861   | 0.333333  |\n-----------------------------------------------------\n| 4   |  16   |  2          | 1.38629   | 0.25      |\n-----------------------------------------------------\n| 5   |  25   |  2.23607    | 1.60944   | 0.2       |\n-----------------------------------------------------\n| 6   |  36   |  2.44949    | 1.79176   | 0.166667  |\n-----------------------------------------------------\n| 7   |  49   |  2.64575    | 1.94591   | 0.142857  |\n-----------------------------------------------------\n| 8   |  64   |  2.82843    | 2.07944   | 0.125     |\n-----------------------------------------------------\n| 9   |  81   |  3          | 2.19722   | 0.111111  |\n-----------------------------------------------------\n| 10  |  100  |  3.16228    | 2.30259   | 0.1       |\n-----------------------------------------------------\n| 11  |  121  |  3.31662    | 2.3979    | 0.0909091 |\n-----------------------------------------------------\n| 12  |  144  |  3.4641     | 2.48491   | 0.0833333 |\n-----------------------------------------------------\n\nThis implies that formats and the variables from which they're filled need to be interleaved.\nThat is, a multi-line specification like this:\n\nprint form\n\"Passed:                      ##\n[[[[[[[[[[[[[[[             # single format specification\nFailed:                        # (needs two sets of data)\n[[[[[[[[[[[[[[[\",          ##\n\n\\@passes, \\@fails;            ##  data for previous format\n\nwould print:\n\nPassed:\n<pass 1>\nFailed:\n<fail 1>\nPassed:\n<pass 2>\nFailed:\n<fail 2>\nPassed:\n<pass 3>\nFailed:\n<fail 3>\n\nbecause the four-line format specifier is treated as a single unit, to be repeatedly filled\nuntil all the data in @passes and @fails has been consumed.\n\nUnlike the table example, where this unit filling correctly put a line of dashes between lines\nof data, in this case the alternation of passes and fails is probably *not* the desired effect.\n\nJudging by the labels, it is far more likely that the user wanted:\n\nPassed:\n<pass 1>\n<pass 2>\n<pass 3>\nFailed:\n<fail 4>\n<fail 5>\n<fail 6>\n\nTo achieve that, either explicitly interleave the formats and their data sources:\n\nprint form\n\"Passed:\",               ## single format (no data required)\n\"   [[[[[[[[[[[[[[[\",    ## single format (needs one set of data)\n\\@passes,            ## data for previous format\n\"Failed:\",               ## single format (no data required)\n\"   [[[[[[[[[[[[[[[\",    ## single format (needs one set of data)\n\\@fails;             ## data for previous format\n\nor instruct \"form\" to do it for you automagically, by setting the 'interleave' flag true:\n\nprint form {interleave=>1}\n\"Passed:                 ##\n[[[[[[[[[[[[[[[        # single format\nFailed:                   # (needs two sets of data)\n[[[[[[[[[[[[[[[\",     ##\n\n## data to be automagically interleaved\n\\@passes, \\@fails;        # as necessary between lines of previous\n## format\n\nHow \"form\" hyphenates\nAny line with a block field repeats on subsequent lines until all block fields on that line have\nconsumed all their data. Non-block fields on these lines are replaced by the appropriate number\nof spaces.\n\nWords are wrapped whole, unless they will not fit into the field at all, in which case they are\nbroken and (by default) hyphenated. Simple hyphenation is used (i.e. break at the *N-1*th\ncharacter and insert a '-'), unless a suitable alternative subroutine is specified instead.\n\nWords will not be broken if the break would leave less than 2 characters on the current line.\nThis minimum can be varied by setting the 'minbreak' option to a numeric value indicating the\nminimum total broken characters (including hyphens) required on the current line. Note that, for\nvery narrow fields, words will still be broken (but *unhyphenated*). For example:\n\nprint form '~', 'split';\n\nwould print:\n\ns\np\nl\ni\nt\n\nwhilst:\n\nprint form {minbreak=>1}, '~', 'split';\n\nwould print:\n\ns-\np-\nl-\ni-\nt\n\nAlternative breaking subroutines can be specified using the \"break\" option in a configuration\nhash. For example:\n\nform { break => \\&mylinebreaker }\n$formatstr,\n@data;\n\n\"form\" expects any user-defined line-breaking subroutine to take three arguments (the string to\nbe broken, the maximum permissible length of the initial section, and the total width of the\nfield being filled). The \"hypenate\" sub must return a list of two strings: the initial (broken)\nsection of the word, and the remainder of the string respectively).\n\nFor example:\n\nsub tildebreak = sub($$$)\n{\n(substr($[0],0,$[1]-1).'~', substr($[0],$[1]-1));\n}\n\nform { break => \\&tildebreak }\n$formatstr,\n@data;\n\nmakes '~' the hyphenation character, whilst:\n\nsub wrapandslop = sub($$$)\n{\nmy ($text, $reqlen, $fldlen) = @;\nif ($reqlen==$fldlen) { $text =~ m/\\A(\\s*\\S*)(.*)/s }\nelse                  { (\"\", $text) }\n}\n\nform { break => \\&wrapandslop }\n$formatstr,\n@data;\n\nwraps excessively long words to the next line and \"slops\" them over the right margin if\nnecessary.\n\nThe Text::Reform package provides three functions to simplify the use of variant hyphenation\nschemes. The exportable subroutine \"Text::Reform::breakwrap\" generates a reference to a\nsubroutine implementing the \"wrap-and-slop\" algorithm shown in the last example, which could\ntherefore be rewritten:\n\nuse Text::Reform qw( form breakwrap );\n\nform { break => breakwrap }\n$formatstr,\n@data;\n\nThe subroutine \"Text::Reform::breakwith\" takes a single string argument and returns a reference\nto a sub which hyphenates by cutting off the text at the right margin and appending the string\nargument. Hence the first of the two examples could be rewritten:\n\nuse Text::Reform qw( form breakwith );\n\nform { break => breakwith('~') }\n$formatstr,\n@data;\n\nThe subroutine \"Text::Reform::breakat\" takes a single string argument and returns a reference\nto a sub which hyphenates by breaking immediately after that string. For example:\n\nuse Text::Reform qw( form breakat );\n\nform { break => breakat('-') }\n\"[[[[[[[[[[[[[[\",\n\"The Newton-Raphson methodology\";\n\n# returns:\n#\n#       \"The Newton-\n#        Raphson\n#        methodology\"\n\nNote that this differs from the behaviour of \"breakwith\", which would be:\n\nform { break => breakwith('-') }\n\"[[[[[[[[[[[[[[\",\n\"The Newton-Raphson methodology\";\n\n# returns:\n#\n#       \"The Newton-R-\n#        aphson metho-\n#        dology\"\n\nHence \"breakat\" is generally a better choice.\n\n\"breakat\" also takes an 'except' option, which tells the resulting subroutine not to break in\nthe middle of certain strings. For example:\n\nform { break => breakat('-', {except=>qr/Newton-Raphson/}) }\n\"[[[[[[[[[[[[[[\",\n\"The Newton-Raphson methodology\";\n\n# returns:\n#\n#       \"The\n#        Newton-Raphson\n#        methodology\"\n\nThis option is particularly useful for preserving URLs.\n\nThe subroutine \"Text::Reform::breakTeX\" returns a reference to a sub which hyphenates using Jan\nPazdziora's TeX::Hyphen module. For example:\n\nuse Text::Reform qw( form breakwrap );\n\nform { break => breakTeX }\n$formatstr,\n@data;\n\nNote that in the previous examples there is no leading '\\&' before \"breakwrap\", \"breakwith\",\nor \"breakTeX\", since each is being directly *called* (and returns a reference to some other\nsuitable subroutine);\n\nThe \"form\" formatting algorithm\nThe algorithm \"form\" uses is:\n\n1. If interleaving is specified, split the first string in the\nargument list into individual format lines and add a\nterminating newline (unless one is already present).\nOtherwise, treat the entire string as a single \"line\" (like\n/s does in regexes)\n\n2. For each format line...\n\n2.1. determine the number of fields and shift\nthat many values off the argument list and\ninto the filling list. If insufficient\narguments are available, generate as many\nempty strings as are required.\n\n2.2. generate a text line by filling each field\nin the format line with the initial contents\nof the corresponding arg in the filling list\n(and remove those initial contents from the arg).\n\n2.3. replace any <,>, or ^ fields by an equivalent\nnumber of spaces. Splice out the corresponding\nargs from the filling list.\n\n2.4. Repeat from step 2.2 until all args in the\nfilling list are empty.\n\n3. concatenate the text lines generated in step 2\n\n4. repeat from step 1 until the argument list is empty\n\n\"form\" examples\nAs an example of the use of \"form\", the following:\n\n$count = 1;\n$text = \"A big long piece of text to be formatted exquisitely\";\n\nprint form q\nq{       ||||  <<<<<<<<<<   },\n$count, $text,\nq{       ----------------   },\nq{       ^^^^  ]]]]]]]]]]|  },\n$count+11, $text,\nq{                       =\n]]].[[[            },\n\"123 123.4\\n123.456789\";\n\nproduces the following output:\n\n1    A big long\n----------------\n12     piece of|\ntext to be|\nformatted|\nexquisite-|\nly|\n=\n123.0\n=\n123.4\n=\n123.456\n\nNote that block fields in a multi-line format string, cause the entire multi-line format to be\nrepeated as often as necessary.\n\nPicture strings and replacement values are interleaved in the traditional \"format\" format, but\ncare is needed to ensure that the correct number of substitution values are provided. Another\nexample:\n\n$report = form\n'Name           Rank    Serial Number',\n'====           ====    =============',\n'<<<<<<<<<<<<<  ^^^^    <<<<<<<<<<<<<',\n$name,         $rank,  $serialnumber,\n''\n'Age    Sex     Description',\n'===    ===     ===========',\n'^^^    ^^^     [[[[[[[[[[[',\n$age,  $sex,   $description;\n\nHow \"form\" consumes strings\nUnlike \"format\", within \"form\" non-block fields *do* consume the text they format, so the\nfollowing:\n\n$text = \"a line of text to be formatted over three lines\";\nprint form \"<<<<<<<<<<\\n  <<<<<<<<\\n    <<<<<<\\n\",\n$text,        $text,        $text;\n\nproduces:\n\na line of\ntext to\nbe fo-\n\nnot:\n\na line of\na line\na line\n\nTo achieve the latter effect, convert the variable arguments to independent literals (by\ndouble-quoted interpolation):\n\n$text = \"a line of text to be formatted over three lines\";\nprint form \"<<<<<<<<<<\\n  <<<<<<<<\\n    <<<<<<\\n\",\n\"$text\",      \"$text\",      \"$text\";\n\nAlthough values passed from variable arguments are progressively consumed *within* \"form\", the\nvalues of the original variables passed to \"form\" are *not* altered. Hence:\n\n$text = \"a line of text to be formatted over three lines\";\nprint form \"<<<<<<<<<<\\n  <<<<<<<<\\n    <<<<<<\\n\",\n$text,        $text,        $text;\nprint $text, \"\\n\";\n\nwill print:\n\na line of\ntext to\nbe fo-\na line of text to be formatted over three lines\n\nTo cause \"form\" to consume the values of the original variables passed to it, pass them as\nreferences. Thus:\n\n$text = \"a line of text to be formatted over three lines\";\nprint form \"<<<<<<<<<<\\n  <<<<<<<<\\n    <<<<<<\\n\",\n\\$text,       \\$text,       \\$text;\nprint $text, \"\\n\";\n\nwill print:\n\na line of\ntext to\nbe fo-\nrmatted over three lines\n\nNote that, for safety, the \"non-consuming\" behaviour takes precedence, so if a variable is\npassed to \"form\" both by reference *and* by value, its final value will be unchanged.\n"
                },
                {
                    "name": "Numerical formatting",
                    "content": "The \">>>.<<<\" and \"]]].[[[\" field specifiers may be used to format numeric values about a fixed\ndecimal place marker. For example:\n\nprint form '(]]]]].[[)', <<EONUMS;\n1\n1.0\n1.001\n1.009\n123.456\n1234567\none two\nEONUMS\n\nwould print:\n\n(    1.0 )\n(    1.0 )\n(    1.00)\n(    1.01)\n(  123.46)\n(#####.##)\n(?????.??)\n(?????.??)\n\nFractions are rounded to the specified number of places after the decimal, but only significant\ndigits are shown. That's why, in the above example, 1 and 1.0 are formatted as \"1.0\", whilst\n1.001 is formatted as \"1.00\".\n\nYou can specify that the maximal number of decimal places always be used by giving the\nconfiguration option 'numeric' a value that matches /\\bAllPlaces\\b/i. For example:\n\nprint form { numeric => AllPlaces },\n'(]]]]].[[)', <<'EONUMS';\n1\n1.0\nEONUMS\n\nwould print:\n\n(    1.00)\n(    1.00)\n\nNote that although decimal digits are rounded to fit the specified width, the integral part of a\nnumber is never modified. If there are not enough places before the decimal place to represent\nthe number, the entire number is replaced with hashes.\n\nIf a non-numeric sequence is passed as data for a numeric field, it is formatted as a series of\nquestion marks. This querulous behaviour can be changed by giving the configuration option\n'numeric' a value that matches /\\bSkipNaN\\b/i in which case, any invalid numeric data is simply\nignored. For example:\n\nprint form { numeric => 'SkipNaN' }\n'(]]]]].[[)',\n<<EONUMS;\n1\ntwo three\n4\nEONUMS\n\nwould print:\n\n(    1.0 )\n(    4.0 )\n"
                },
                {
                    "name": "Filling block fields with lists of values",
                    "content": "If an argument corresponding to a field is an array reference, then \"form\" automatically joins\nthe elements of the array into a single string, separating each element with a newline\ncharacter. As a result, a call like this:\n\n@values = qw( 1 10 100 1000 );\nprint form \"(]]]].[[)\", \\@values;\n\nwill print out\n\n(   1.00)\n(  10.00)\n( 100.00)\n(1000.00)\n\nas might be expected.\n\nNote however that arrays must be passed by reference (so that \"form\" knows that the entire array\nholds data for a single field). If the previous example had not passed @values by reference:\n\n@values = qw( 1 10 100 1000 );\nprint form \"(]]]].[[)\", @values;\n\nthe output would have been:\n\n(   1.00)\n10\n100\n1000\n\nThis is because @values would have been interpolated into \"form\"'s argument list, so only\n$value[0] would have been used as the data for the initial format string. The remaining elements\nof @value would have been treated as separate format strings, and printed out \"verbatim\".\n\nNote too that, because arrays must be passed using a reference, their original contents are\nconsumed by \"form\", just like the contents of scalars passed by reference.\n\nTo avoid having an array consumed by \"form\", pass it as an anonymous array:\n\nprint form \"(]]]].[[)\", [@values];\n"
                },
                {
                    "name": "Headers, footers, and pages",
                    "content": "The \"form\" subroutine can also insert headers, footers, and page-feeds as it formats. These\nfeatures are controlled by the \"header\", \"footer\", \"pagefeed\", \"pagelen\", and \"pagenum\" options.\n\nThe \"pagenum\" option takes a scalar value or a reference to a scalar variable and starts page\nnumbering at that value. If a reference to a scalar variable is specified, the value of that\nvariable is updated as the formatting proceeds, so that the final page number is available in it\nafter formatting. This can be useful for multi-part reports.\n\nThe \"pagelen\" option specifies the total number of lines in a page (including headers, footers,\nand page-feeds).\n\nThe \"pagewidth\" option specifies the total number of columns in a page.\n\nIf the \"header\" option is specified with a string value, that string is used as the header of\nevery page generated. If it is specified as a reference to a subroutine, that subroutine is\ncalled at the start of every page and its return value used as the header string. When called,\nthe subroutine is passed the current page number.\n\nLikewise, if the \"footer\" option is specified with a string value, that string is used as the\nfooter of every page generated. If it is specified as a reference to a subroutine, that\nsubroutine is called at the *start* of every page and its return value used as the footer\nstring. When called, the footer subroutine is passed the current page number.\n\nBoth the header and footer options can also be specified as hash references. In this case the\nhash entries for keys \"left\", \"centre\" (or \"center\"), and \"right\" specify what is to appear on\nthe left, centre, and right of the header/footer. The entry for the key \"width\" specifies how\nwide the footer is to be. If the \"width\" key is omitted, the \"pagewidth\" configuration option\n(which defaults to 72 characters) is used.\n\nThe \"left\", \"centre\", and \"right\" values may be literal strings, or subroutines (just as a\nnormal header/footer specification may be.) See the second example, below.\n\nAnother alternative for header and footer options is to specify them as a subroutine that\nreturns a hash reference. The subroutine is called for each page, then the resulting hash is\ntreated like the hashes described in the preceding paragraph. See the third example, below.\n\nThe \"pagefeed\" option acts in exactly the same way, to produce a pagefeed which is appended\nafter the footer. But note that the pagefeed is not counted as part of the page length.\n\nAll three of these page components are recomputed at the start of each new page, before the page\ncontents are formatted (recomputing the header and footer first makes it possible to determine\nhow many lines of data to format so as to adhere to the specified page length).\n\nWhen the call to \"form\" is complete and the data has been fully formatted, the footer subroutine\nis called one last time, with an extra argument of 1. The string returned by this final call is\nused as the final footer.\n\nSo for example, a 60-line per page report, starting at page 7, with appropriate headers and\nfooters might be set up like so:\n\n$page = 7;\n\nform { header => sub { \"Page $[0]\\n\\n\" },\nfooter => sub { my ($pagenum, $lastpage) = @;\nreturn \"\" if $lastpage;\nreturn \"-\"x50 . \"\\n\"\n.form \">\"x50, \"...\".($pagenum+1);\n},\npagefeed => \"\\n\\n\",\npagelen  => 60\npagenum => \\$page,\n},\n$template,\n@data;\n\nNote the recursive use of \"form\" within the \"footer\" option!\n\nAlternatively, to set up headers and footers such that the running head is right justified in\nthe header and the page number is centred in the footer:\n\nform { header => { right => \"Running head\" },\nfooter => { centre => sub { \"Page $[0]\" } },\npagelen  => 60\n},\n$template,\n@data;\n\nThe footer in the previous example could also have been specified the other way around, as a\nsubroutine that returns a hash (rather than a hash containing a subroutine):\n\nform { header => { right => \"Running head\" },\nfooter => sub { return {centre => \"Page $[0]\"} },\npagelen  => 60\n},\n$template,\n@data;\n\nThe \"cols\" option\nSometimes data to be used in a \"form\" call needs to be extracted from a nested data structure.\nFor example, whilst it's easy to print a table if you already have the data in columns:\n\n@name  = qw(Tom Dick Harry);\n@score = qw( 88   54    99);\n@time  = qw( 15   13    18);\n\nprint form\n'-------------------------------',\n'Name             Score     Time',\n'-------------------------------',\n'[[[[[[[[[[[[[[   |||||     ||||',\n\\@name,          \\@score,  \\@time;\n\nif the data is aggregrated by rows:\n\n@data = (\n{ name=>'Tom',   score=>88, time=>15 },\n{ name=>'Dick',  score=>54, time=>13 },\n{ name=>'Harry', score=>99, time=>18 },\n);\n\nyou need to do some fancy mapping before it can be fed to \"form\":\n\nprint form\n'-------------------------------',\n'Name             Score     Time',\n'-------------------------------',\n'[[[[[[[[[[[[[[   |||||     ||||',\n[map $${name},  @data],\n[map $${score}, @data],\n[map $${time} , @data];\n\nOr you could just use the 'cols' option:\n\nuse Text::Reform qw(form columns);\n\nprint form\n'-------------------------------',\n'Name             Score     Time',\n'-------------------------------',\n'[[[[[[[[[[[[[[   |||||     ||||',\n{ cols => [qw(name score time)],\nfrom => \\@data\n};\n\nThis option takes an array of strings that specifies the keys of the hash entries to be\nextracted into columns. The 'from' entry (which must be present) also takes an array, which is\nexpected to contain a list of references to hashes. For each key specified, this option inserts\ninto \"form\"'s argument list a reference to an array containing the entries for that key,\nextracted from each of the hash references supplied by 'from'. So, for example, the option:\n\n{ cols => [qw(name score time)],\nfrom => \\@data\n}\n\nis replaced by three array references, the first containing the 'name' entries for each hash\ninside @data, the second containing the 'score' entries for each hash inside @data, and the\nthird containing the 'time' entries for each hash inside @data.\n\nIf, instead, you have a list of arrays containing the data:\n\n@data = (\n# Time  Name     Score\n[ 15,   'Tom',   88 ],\n[ 13,   'Dick',  54 ],\n[ 18,   'Harry', 99 ],\n);\n\nthe 'cols' option can extract the appropriate columns for that too. You just specify the\nrequired indices, rather than keys:\n\nprint form\n'-----------------------------',\n'Name             Score   Time',\n'-----------------------------',\n'[[[[[[[[[[[[[[   |||||   ||||',\n{ cols => [1,2,0],\nfrom => \\@data\n}\n\nNote that the indices can be in any order, and the resulting arrays are returned in the same\norder.\n\nIf you need to merge columns extracted from two hierarchical data structures, just concatenate\nthe data structures first, like so:\n\nprint form\n'---------------------------------------',\n'Name             Score   Time   Ranking\n'---------------------------------------',\n'[[[[[[[[[[[[[[   |||||   ||||   |||||||',\n{ cols => [1,2,0],\nfrom => [@data, @olddata],\n}\n\nOf course, this only works if the columns are in the same positions in both data sets (and both\ndatasets are stored in arrays) or if the columns have the same keys (and both datasets are in\nhashes). If not, you would need to format each dataset separately, like so:\n\nprint form\n'-----------------------------',\n'Name             Score   Time'\n'-----------------------------',\n'[[[[[[[[[[[[[[   |||||   ||||',\n{ cols=>[1,2,0],  from=>\\@data },\n'[[[[[[[[[[[[[[   |||||   ||||',\n{ cols=>[3,8,1],  from=>\\@olddata },\n'[[[[[[[[[[[[[[   |||||   ||||',\n{ cols=>[qw(name score time)],  from=>\\@otherdata };\n\nThe \"tag\" sub\nThe \"tag\" subroutine may be exported from the module. It takes two arguments: a tag specifier\nand a text to be entagged. The tag specifier indicates the indenting of the tag, and of the\ntext. The sub generates an end-tag (using the usual \"/*tag*\" variant), unless an explicit\nend-tag is provided as the third argument.\n\nThe tag specifier consists of the following components (in order):\n\nAn optional vertical spacer (zero or more whitespace-separated newlines)\nOne or more whitespace characters up to a final mandatory newline. This vertical space is\ninserted before the tag and after the end-tag\n\nAn optional tag indent\nZero or more whitespace characters. Both the tag and the end-tag are indented by this\nwhitespace.\n\nAn optional left (opening) tag delimiter\nZero or more non-\"word\" characters (not alphanumeric or ''). If the opening delimiter is\nomitted, the character '<' is used.\n\nA tag\nOne or more \"word\" characters (alphanumeric or '').\n\nOptional tag arguments\nAny number of any characters\n\nAn optional right (closing) tag delimiter\nZero or more non-\"word\" characters which balance some sequential portion of the opening tag\ndelimiter. For example, if the opening delimiter is \"<-(\" then any of the following are\nacceptible closing delimiters: \")->\", \"->\", or \">\". If the closing delimiter is omitted, the\n\"inverse\" of the opening delimiter is used (for example, \")->\"),\n\nAn optional vertical spacer (zero or more newlines)\nOne or more whitespace characters up to a mandatory newline. This vertical space is inserted\nbefore and after the complete text.\n\nAn optional text indent\nZero or more space of tab characters. Each line of text is indented by this whitespace (in\naddition to the tag indent).\n\nFor example:\n\n$text = \"three lines\\nof tagged\\ntext\";\n\nprint tag \"A HREF=#nextsection\", $text;\n\nprints:\n\n<A HREF=#nextsection>three lines\nof tagged\ntext</A>\n\nwhereas:\n\nprint tag \"[-:GRIN>>>\\n\", $text;\n\nprints:\n\n[-:GRIN>>>:-]\nthree lines\nof tagged\ntext\n[-:/GRIN>>>:-]\n\nand:\n\nprint tag \"\\n\\n   <BOLD>\\n\\n   \", $text, \"<END BOLD>\";\n\nprints:\n\n\n\n<BOLD>\n\nthree lines\nof tagged\ntext\n\n<END BOLD>\n\n\n\n(with the indicated spacing fore and aft).\n"
                }
            ]
        },
        "AUTHOR": {
            "content": "Damian Conway (damian@conway.org)\n",
            "subsections": []
        },
        "BUGS": {
            "content": "The module uses \"POSIX::strtod\", which may be broken under certain versions of Windows. Applying\nthe WINDOWSPATCH patch to Reform.pm will replace the POSIX function with a copycat subroutine.\n\nThere are undoubtedly serious bugs lurking somewhere in code this funky :-) Bug reports and\nother feedback are most welcome.\n",
            "subsections": []
        },
        "LICENCE AND COPYRIGHT": {
            "content": "Copyright (c) 1997-2007, Damian Conway \"<DCONWAY@CPAN.org>\". All rights reserved.\n\nThis module is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself. See perlartistic.\n",
            "subsections": []
        },
        "DISCLAIMER OF WARRANTY": {
            "content": "BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE\nEXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER\nEXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\nSOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY\nSERVICING, REPAIR, OR CORRECTION.\n\nIN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER,\nOR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE\nLICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR\nCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT\nLIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR\nOTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.\n",
            "subsections": []
        }
    },
    "summary": "Text::Reform - Manual text wrapping and reformatting",
    "flags": [],
    "examples": [],
    "see_also": []
}