.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "ShowTable 3pm" .TH ShowTable 3pm "2022-10-13" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" ShowTable \- routines to display tabular data in several formats. .SH "USAGE" .IX Header "USAGE" \&\f(CW\*(C`use Data::ShowTable;\*(C'\fR .PP \&\fBShowTable\fR { \fIparameter\fR => \fIvalue\fR, ... }; .PP \&\fBShowTable\fR \fI\e@titles\fR, \fI\e@types\fR, \fI\e@widths\fR, \fI\e&row_sub\fR [, \fI\e&fmt_sub\fR ]; .PP \&\fBShowDatabases\fR \fI\e@dbnames\fR; .PP \&\fBShowDatabases\fR { \fIparameter\fR => \fIvalue\fR, ... }; .PP \&\fBShowTables\fR \fI\e@tblnames\fR; .PP \&\fBShowTables\fR { \fIparameter\fR => \fIvalue\fR, ... }; .PP \&\fBShowColumns\fR \fI\e@columns\fR, \fI\e@col_types\fR, \fI\e@col_lengths\fR, \fI\e@col_attrs\fR; .PP \&\fBShowColumns\fR { \fIparameter\fR => \fIvalue\fR, ... }; .PP \&\fBShowBoxTable\fR \fI\e@titles\fR, \fI\e@types\fR, \fI\e@widths\fR, \fI\e&row_sub\fR [, \fI\e&fmt_sub\fR ]; .PP \&\fBShowBoxTable\fR { \fIparameter\fR => \fIvalue\fR, ... }; .PP \&\fBShowSimpleTable\fR \fI\e@titles\fR, \fI\e@types\fR, \fI\e@widths\fR, \fI\e&row_sub\fR [, \fI\e&fmt_sub\fR]; .PP \&\fBShowSimpleTable\fR { \fIparameter\fR => \fIvalue\fR, ... }; .PP \&\fBShowHTMLTable\fR \fI\e@titles\fR, \fI\e@types\fR, \fI\e@widths\fR, \fI\e&row_sub\fR [, \fI\e&fmt_sub\fR]; .PP \&\fBShowHTMLTable\fR { \fIparameter\fR => \fIvalue\fR, ... }; .PP \&\fBShowListTable\fR \fI\e@titles\fR, \fI\e@types\fR, \fI\e@widths\fR, \fI\e&row_sub\fR [, \fI\e&fmt_sub\fR]; .PP \&\fBShowListTable\fR { \fIparameter\fR => \fIvalue\fR, ... }; .PP \&\f(CW\*(C`package Data::ShowTable\*(C'\fR; .PP \&\fB\f(CB$Show_Mode\fB\fR = '\fImode\fR'; .PP \&\fB\f(CB$Max_Table_Width\fB\fR = \fInumber\fR; .PP \&\fB\f(CB$Max_List_Width\fB\fR = \fInumber\fR; .PP \&\fB\f(CB$No_Escape\fB\fR = \fIflag\fR; .PP \&\fB\f(CB%URL_Keys\fB\fR = { "\fI\f(CI$colname\fI\fR\*(L" => \*(R"\fI\f(CI$col_URL\fI\fR", ... }; .PP \&\fB\f(CB@Title_Formats\fB\fR = ( \fIfmt1_html\fR, , ... ); .PP \&\fB\f(CB@Data_Formats\fB\fR = ( \fIfmt1_html\fR, , ... ); .PP \&\fBShowRow\fR \fI\f(CI$rewindflag\fI\fR, \fI\e$index\fR, \fI\f(CI$col_array_1\fI\fR [, \fI\f(CI$col_array_2\fI\fR, ...;] .PP \&\fI\f(CI$fmt\fI\fR = \fBShowTableValue\fR \fI\f(CI$value\fI\fR, \fI\f(CI$type\fI\fR, \fI\f(CI$max_width\fI\fR, \fI\f(CI$width\fI\fR, \fI\f(CI$precision\fI\fR, \fI\f(CI$showmode\fI\fR; .PP [\fI\f(CI$plaintext\fI\fR = ] \fBPlainText\fR [\fI\f(CI$htmltext\fI\fR]; .SH "DESCRIPTION" .IX Header "DESCRIPTION" The \fBShowTable\fR module provides subroutines to display tabular data, typially from a database, in nicely formatted columns, in several formats. Its arguments can either be given in a fixed order, or, as a single, anonymous hash-array. .PP The output format for any one invocation can be one of four possible styles: .IP "Box" 10 .IX Item "Box" A tabular format, with the column titles and the entire table surrounded by a \&\*(L"box\*(R" of "\f(CW\*(C`+\*(C'\fR\*(L", \*(R"\f(CW\*(C`\-\*(C'\fR\*(L", and \*(R"\f(CW\*(C`|\*(C'\fR" characters. See \*(L"ShowBoxTable\*(R" for details. .IP "Table" 10 .IX Item "Table" A simple tabular format, with columns automatically aligned, with column titles. See \*(L"ShowSimpleTable\*(R". .IP "List" 10 .IX Item "List" A \fIlist\fR style, where columns of data are listed as a \fIname\fR:\fIvalue\fR pair, one pair per line, with rows being one or more column values, separated by an empty line. See \*(L"ShowListTable\*(R". .IP "\s-1HTML\s0" 10 .IX Item "HTML" The data is output as an \s-1HTML\s0 \fI\s-1TABLE\s0\fR, suitable for display through a \fIWeb\fR\-client. See \*(L"ShowHTMLTable\*(R". Input can either be plain \s-1ASCII\s0 text, or text with embedded \s-1HTML\s0 elements, depending upon an argument or global parameter. .PP The subroutines which perform these displays are listed below. .SH "EXPORTED NAMES" .IX Header "EXPORTED NAMES" This module exports the following subroutines: .PP .Vb 11 \& ShowDatabases \- show list of databases \& ShowTables \- show list of tables \& ShowColumns \- show table of column info \& ShowTable \- show a table of data \& ShowRow \- show a row from one or more columns \& ShowTableValue \- show a single column\*(Aqs value \& ShowBoxTable \- show a table of data in a box \& ShowListTable \- show a table of data in a list \& ShowSimpleTable \- show a table of data in a simple table \& ShowHTMLTable \- show a table of data using HTML \& PlainText \- convert HTML text into plain text .Ve .PP All of these subroutines, and others, are described in detail in the following sections. .SH "MODULES" .IX Header "MODULES" .SH "ShowTable" .IX Header "ShowTable" Format and display the contents of one or more rows of data. .PP   \fBShowTable\fR { \fIparameter\fR => \fIvalue\fR, ... }; .PP   \fBShowTable\fR \fI\e@titles\fR, \fI\e@types\fR, \fI\e@widths\fR, \fI\e&row_sub\fR [, \fI\e&fmt_sub\fR [, \fI\f(CI$max_width\fI\fR ] [, \fI\f(CI$show_mode\fI\fR ] ]; .PP The \fBShowTable\fR subroutine displays tabular data aligned in columns, with headers. \fBShowTable\fR supports four \fImodes\fR of display: \fBBox\fR, \fBTable\fR, \&\fBList\fR, and \fB\s-1HTML\s0\fR. Each mode is described separately below. .PP The arguments to \fBShowTable\fR may be given in one of two ways: as a hashed-array, or by a combination of fixed order arguments, and some package-global variable settings. The hash-array parameters correspond to the fixed arguments and the global-parameter settings. .PP In the list below, both the hash-array parameter name and the fixed-order argument name is given as the value. In the case where there is no fixed-order argument for a given parameter-value pair, then the corresponding global variable name is given. .ie n .IP """titles"" => \fI\e@titles\fR" 10 .el .IP "\f(CWtitles\fR => \fI\e@titles\fR" 10 .IX Item "titles => @titles" A reference to an array of column names, or titles. If a particular column name is null, then the string \f(CW\*(C`Field_\f(CInum\f(CW\*(C'\fR is used by default. To have a column have no title, use the empty string. .ie n .IP """types"" => \fI\e@types\fR" 10 .el .IP "\f(CWtypes\fR => \fI\e@types\fR" 10 .IX Item "types => @types" A reference to an array of types, one for each column. These types are passed to the \fIfmt_sub\fR for appropriate formatting. Also, if a column type matches the regexp "\f(CW\*(C`/text|char|string/i\*(C'\fR", then the column alignment will be left-justified, otherwise it will be right-justified. .ie n .IP """widths"" => \fI\e@widths\fR" 10 .el .IP "\f(CWwidths\fR => \fI\e@widths\fR" 10 .IX Item "widths => @widths" A reference to an array of column widths, which may be given as an integer, or as a string of the form: "\fIwidth\fR.\fIprecision\fR". .ie n .IP """row_sub"" => \fI\e&row_sub\fR" 10 .el .IP "\f(CWrow_sub\fR => \fI\e&row_sub\fR" 10 .IX Item "row_sub => &row_sub" A reference to a subroutine which successively returns rows of values in an array. It is called for two purposes, each described separately: .Sp * To fetch successive rows of data: .Sp .Vb 1 \& @row = &$row_sub(0); .Ve .Sp When given a null, zero, or empty argument, the next row is returned. .Sp * To initialize or rewind the data traversal. .Sp .Vb 1 \& $rewindable = &$row_sub(1); .Ve .Sp When invoked with a non-null argument, the subroutine should rewind its row pointer to start at the first row of data. If the data which \&\fIrow_sub\fR is traversing is not rewindable, it must return zero or null. If the data is rewindable, a non-null, non-zero value should be returned. .Sp The \fIrow_sub\fR must expect to be invoked once with a non-null argument, in order to discover whether or not the data is rewindable. If the data cannot be rewound, \fIrow_sub\fR will thereafter only be called with a zero argument. .Sp Specifically, \fIrow_sub\fR subroutine is used in this manner: .Sp .Vb 10 \& $rewindable = &$row_sub(1); \& if ($rewindable) { \& while ((@row = &$row_sub(0)), $#row >= 0) { \& # examine lengths for optimal formatting \& } \& &$row_sub(1); # rewind \& } \& while ((@row = &$row_sub(0)), $#row >= 0) { \& # format the data \& } .Ve .Sp The consequence of data that is not rewindable, a reasonably nice table will still be formatted, but it may contain fairly large amounts of whitespace for wide columns. .ie n .IP """fmtsub"" => \fI\e&fmt_sub\fR" 10 .el .IP "\f(CWfmtsub\fR => \fI\e&fmt_sub\fR" 10 .IX Item "fmtsub => &fmt_sub" A reference to a subroutine which formats a value, according to its type, width, precision, and the current column width. It is invoked either with a fixed list of arguments, or with a hash-array of parameter and value pairs. .Sp .Vb 1 \& $string = &fmt_sub { I => I, ... }; \& \& $string = &fmt_sub($value, $type, $max_width, $width, $precision) .Ve .Sp If \fI\e&fmt_sub\fR is omitted, then a default subroutine, \fBShowTableValue\fR, will be used, which will use Perl's standard string formatting rules. .Sp The arguments to \fI\e&fmt_sub\fR, either as values passed in a fixed order, or as part of the parameter value pair, are described in the section on "ShowTableValue below. .ie n .IP """max_width"" => \fInumber\fR," 10 .el .IP "\f(CWmax_width\fR => \fInumber\fR," 10 .IX Item "max_width => number," The maximum table width, including the table formatting characters. If not given, defaults to the global variable \fB\f(CB$Max_Table_Width\fB\fR; .ie n .IP """show_mode"" => '\fImode\fR'," 10 .el .IP "\f(CWshow_mode\fR => '\fImode\fR'," 10 .IX Item "show_mode => 'mode'," The display mode of the output. One of five strings: \f(CW\*(AqBox\*(Aq\fR, \&\f(CW\*(AqTable\*(Aq\fR, \f(CW\*(AqSimple\*(Aq\fR, \f(CW\*(AqList\*(Aq\fR, and \f(CW\*(AqHTML\*(Aq\fR. .SH "ShowDatabases" .IX Header "ShowDatabases" Show a list of database names. .PP   \fBShowDatabases\fR \fI\e@dbnames\fR; .PP   \fBShowDatabases\fR { 'data' => \fI\e@dbnames\fR, \fIparameter\fR => \&\fIvalue\fR, ...}; .PP \&\fBShowDatabases\fR is intended to be used to display a list of database names, under the column heading of \*(L"Databases\*(R". It is a special case usage of \fBShowTable\fR (and can thus be passed any parameter suitable for \fBShowTable\fR. .PP The argument, \fI\e@dbnames\fR, is a reference to an array of strings, used as the values of the single column display. .SH "ShowTables" .IX Header "ShowTables" Show an array of table names. .PP   \fBShowTables\fR \fI\e@tblnames\fR; .PP   \fBShowTables\fR { 'data' => \fI\e@tblnames\fR, \fIparameter\fR => \fIvalue\fR, ...}; .PP \&\fBShowTables\fR is used to display a list of table names, under the column heading of \*(L"Tables\*(R". It is a special case usage of \fBShowTable\fR, and can be passed any \*(L"ShowTable\*(R" argument parameter. .SH "ShowColumns" .IX Header "ShowColumns" Display a table of column names, types, and attributes. .PP   \fBShowColumns\fR { \fIparameter\fR => \fIvalues\fR, ... }; .PP   \fBShowColumns\fR \fI\e@columns\fR, \fI\e@col_types\fR, \fI\e@col_lengths\fR, \fI\e@col_attrs\fR; .PP The \fBShowColumns\fR subroutine displays a table of column names, types, lengths, and other attributes in a nicely formatted table. It is a special case usage of \fBShowTable\fR, and can be passed any argument suitable for \*(L"ShowTable\*(R"; .PP The arguments are: .ie n .IP """columns"" = \fI\e@columns\fR" 10 .el .IP "\f(CWcolumns\fR = \fI\e@columns\fR" 10 .IX Item "columns = @columns" An array of column names. This provides the value for the first column of the output. .ie n .IP """col_types"" = \fI\e@col_types\fR" 10 .el .IP "\f(CWcol_types\fR = \fI\e@col_types\fR" 10 .IX Item "col_types = @col_types" An array of column types names. This provides the value for the second column. .ie n .IP """col_lengths"" = \fI\e@col_lengths\fR" 10 .el .IP "\f(CWcol_lengths\fR = \fI\e@col_lengths\fR" 10 .IX Item "col_lengths = @col_lengths" An array of maximum lengths for corresponding columns. This provides the value for the third column of the output. .ie n .IP """col_attrs"" = \fI\e@col_attrs\fR" 10 .el .IP "\f(CWcol_attrs\fR = \fI\e@col_attrs\fR" 10 .IX Item "col_attrs = @col_attrs" An array of column attributes array references (ie: an array of arrays). The attributes array for the first column are at "\fI\f(CI$col_attrs\fI\fR\-\e>[0]\*(L". The first attribute of the second column is \*(R"\fI\f(CI$col_attrs\fI\fR\-\e>[1][0]". .PP The columns, types, lengths, and attributes are displayed in a table with the column headings: \*(L"Column\*(R", \*(L"Type\*(R", \*(L"Length\*(R", and \*(L"Attributes\*(R". This is a special case usage of \fBShowTable\fR, and can be passed additional arguments suitable for \*(L"ShowTable\*(R". .SH "ShowBoxTable" .IX Header "ShowBoxTable" Show tabular data in a box. .PP   \fBShowBoxTable\fR { \fIparameter\fR = \fIvalue\fR, ... }; .PP   \fBShowBoxTable\fR \fI\e@titles\fR, \fI\e@types\fR, \fI\e@widths\fR, \fI\e&row_sub\fR       [, [ \fI\e&fmt_sub\fR ] [, \fI\f(CI$max_width\fI\fR ] ]; .PP The \fBShowBoxTable\fR displays tabular data in titled columns using a \*(L"box\*(R" of \s-1ASCII\s0 graphics, looking something like this: .PP .Vb 9 \& +\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-+ \& | Column1 | Column2 | ... | ColumnN | \& +\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-+ \& | Value11 | Value12 | ... | Value 1M | \& | Value21 | Value22 | ... | Value 2M | \& | Value31 | Value32 | ... | Value 3M | \& | ... | ... | ... | ... | \& | ValueN1 | ValueN2 | ... | Value NM | \& +\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-+ .Ve .PP The arguments are the same as with \*(L"ShowTable\*(R". If the \fI\f(CI@titles\fI\fR array is empty, the header row is omitted. .SH "ShowSimpleTable" .IX Header "ShowSimpleTable" Display a table of data using a simple table format. .PP   \fBShowSimpleTable\fR \fI\e@titles\fR, \fI\e@types\fR, \fI\e@widths\fR, \fI\e&row_sub\fR [, \fI\e&fmt_sub\fR]; .PP   \fBShowSimpleTable\fR { \fIparameter\fR => \fIvalues\fR, ... }; .PP The \fBShowSimpleTable\fR subroutine formats data into a simple table of aligned columns, in the following example: .PP .Vb 4 \& Column1 Column2 Column3 \& \-\-\-\-\-\-\- \-\-\-\-\-\-\- \-\-\-\-\-\-\- \& Value1 Value2 Value3 \& Value12 Value22 Value32 .Ve .PP Columns are auto-sized by the data's widths, plus two spaces between columns. Values which are too long for the maximum colulmn width are wrapped within the column. .SH "ShowHTMLTable" .IX Header "ShowHTMLTable" Display a table of data nicely using \s-1HTML\s0 tables. .PP   \fBShowHTMLTable\fR { \fIparameter\fR => \fIvalue\fR, ... }; .PP   \fBShowHTMLTable\fR \fI\e@titles\fR, \fI\e@types\fR, \fI\e@widths\fR, \fI\e&row_sub\fR [, \fI\e&fmt_sub\fR [, \fI\f(CI$max_width\fI\fR [, \fI\e%URL_Keys\fR [, \fI\f(CI$no_escape\fI\fR [, \fI\e@title_formats\fR [, \fI\e@data_formats\fR [, \fI\f(CI$table_attrs\fI\fR ] ] ] ] ] ] ]; .PP The \fBShowHTMLTable\fR displays one or more rows of columns of data using the \s-1HTML\s0 \f(CW\*(C`\e feature. In addition to the usual parameter arguments of \*(L"ShowTable\*(R", the following parameter arguments are defined: .ie n .IP """url_keys"" => \fI\e%URL_Keys\fR," 10 .el .IP "\f(CWurl_keys\fR => \fI\e%URL_Keys\fR," 10 .IX Item "url_keys => %URL_Keys," This is a hash array of column names (titles) and corresponding base URLs. The values of any column names or indexes occuring as keys in the hash array will be generated as hypertext anchors using the associated \fIprintf\fR\-like string as the base \s-1URL.\s0 Either the column name or the column index (beginning with 1) may be used as the hash key. .Sp In the string value, these macros can be substituted: .Sp "\f(CW%K\fR" is replaced with the column name. .Sp "\f(CW%V\fR" is replaced with the column value; .Sp "\f(CW%I\fR" is replaced with the column index. .Sp For example, if we define the array: .Sp .Vb 3 \& $base_url = "http://www.$domain/cgi/lookup?col=%K?val=%V"; \& %url_cols = (\*(AqAuthor\*(Aq => $base_url, \& \*(AqName\*(Aq => $base_url); .Ve .Sp Then, the values in the \f(CW\*(C`Author\*(C'\fR column will be generated with the following \&\s-1HTML\s0 text: .Sp .Vb 1 \& othervalue .Ve .Sp If this variable is not given, it will default to the global variable \&\f(CW\*(C`\e%URL_Keys\*(C'\fR. .ie n .IP """no_escape"" => \fIboolean\fR," 10 .el .IP "\f(CWno_escape\fR => \fIboolean\fR," 10 .IX Item "no_escape => boolean," Unless \fB\f(CB$no_escape\fB\fR is set, HTML-escaping is performed on the data values in order to properly display the special \s-1HTML\s0 formatting characters : '\e<', '\e>', and '&'. If you wish to display data with embedded \s-1HTML\s0 text, you must set \fB\f(CB$no_escape\fB\fR. .Sp Enabling embedded \s-1HTML,\s0 turns on certain heuristics which enable the user to more completely define appearance of the table. For instance, any \f(CW\*(C`\e tokens found embedded *anywhere* within a row of data will be placed at the front of the row, within the generated \f(CW\*(C`\e. .Sp Similarly, a row of data containing the \f(CW\*(C`\e or \f(CW\*(C`\e tokens, and their closing counterparts, will begin and end, respectively a table header or footer data. .ie n .IP """title_formats"" => \fI\e@title_formats\fR," 10 .el .IP "\f(CWtitle_formats\fR => \fI\e@title_formats\fR," 10 .IX Item "title_formats => @title_formats," .PD 0 .ie n .IP """tformats"" => \fI\e@title_formats\fR," 10 .el .IP "\f(CWtformats\fR => \fI\e@title_formats\fR," 10 .IX Item "tformats => @title_formats," .PD An array of \s-1HTML\s0 formatting elements for the column titles, one for each column. Each array element is a list of one or more \s-1HTML\s0 elements, given as \f(CW\*(C`\e or plainly, \f(CW\*(C`ELEMENT\*(C'\fR, and separated by a comma \&\f(CW\*(Aq,\*(Aq\fR, semi-colon \f(CW\*(Aq;\*(Aq\fR, or vertical bar \f(CW\*(Aq|\*(Aq\fR. Each given \s-1HTML\s0 element is prepended to the corresponding column title, in the order given. The corresponding \s-1HTML\s0 closing elements are appended in the opposite order. .Sp For example, if \fI\e@title_formats\fR contains the two elements: .Sp .Vb 1 \& [ \*(AqFONT SIZE=+2,BOLD\*(Aq, \*(AqFONT COLOR=red,EM\*(Aq ] .Ve .Sp then the text output for the title of the first column would be: .Sp .Vb 1 \& I .Ve .Sp If \f(CW\*(C`title_formats\*(C'\fR is omitted, the global variable \fB\f(CB@Title_Formats\fB\fR is used by default. .ie n .IP """data_formats"" => \fI\e@data_formats\fR," 10 .el .IP "\f(CWdata_formats\fR => \fI\e@data_formats\fR," 10 .IX Item "data_formats => @data_formats," .PD 0 .ie n .IP """dformats"" => \fI\e@data_formats\fR," 10 .el .IP "\f(CWdformats\fR => \fI\e@data_formats\fR," 10 .IX Item "dformats => @data_formats," .PD Similar to \f(CW\*(C`title_formats\*(C'\fR, this array provides \s-1HTML\s0 formatting for the columns of each row of data. If \f(CW\*(C`data_formats\*(C'\fR is omitted or null, then the global variable \fB\e@Data_Formats\fR is used by default. .ie n .IP """table_attrs"" => \fI\f(CI$table_attrs\fI\fR," 10 .el .IP "\f(CWtable_attrs\fR => \fI\f(CI$table_attrs\fI\fR," 10 .IX Item "table_attrs => $table_attrs," This variable defines a string of attributes to be inserted within the \&\f(CW\*(C`\e token. For example, if the user wishes to have no table border: .Sp .Vb 5 \& ShowHTMLTable { \& ... \& table_attrs => \*(AqBORDER=0\*(Aq, \& ... \& }; .Ve .SH "ShowListTable" .IX Header "ShowListTable" Display a table of data using a list format. .PP   \fBShowListTable\fR { \fIparameter\fR => \fIvalue\fR, ... }; .PP   \fBShowListTable\fR \fI\e@titles\fR, \fI\e@types\fR, \fI\e@widths\fR, \fI\e&row_sub\fR [, \fI\e&fmt_sub\fR [, \fI\f(CI$max_width\fI\fR [, \fI\f(CI$wrap_margin\fI\fR ] ] ]; .PP The arguments for \fBShowListTable\fR are the same as for \*(L"ShowTable\*(R", except for those described next. .ie n .IP """max_width"" = \fInumber\fR," 10 .el .IP "\f(CWmax_width\fR = \fInumber\fR," 10 .IX Item "max_width = number," .PD 0 .ie n .IP """wrap_margin"" = \fInumber\fR," 10 .el .IP "\f(CWwrap_margin\fR = \fInumber\fR," 10 .IX Item "wrap_margin = number," .PD Lines are truncated, and wrapped when their length exceeds \&\fI\f(CI$max_width\fI\fR. Wrapping is done on a word-basis, unless the resulting right margin exceeds \fI\f(CI$wrap_margin\fI\fR, in which case the line is simply truncated at the \fI\f(CI$max_width\fI\fR limit. .Sp The \fI\f(CI$max_width\fI\fR variable defaults to \fB\f(CB$Max_List_Width\fB\fR. The \&\fI\f(CI$wrap_margin\fI\fR defaults to \fB\f(CB$List_Wrap_Margin\fB\fR. .PP In \fIList\fR mode, columns (called \*(L"fields\*(R" in List mode) are displayed wth a field name and value pair per line, with records being one or more fields . In other words, the output of a table would look something like this: .PP .Vb 10 \& Field1_1: Value1_1 \& Field1_2: Value1_2 \& Field1_3: Value1_3 \& ... \& Field1\-N: Value1_M \& \& Field2_1: Value2_1 \& Field2_2: Value2_2 \& Field2_3: Value2_3 \& ... \& Field2_N: Value2_N \& ... \& FieldM_1: ValueM_1 \& FieldM_2: ValueM_2 \& ... \& FieldM_N: ValueM_N \& \& .Ve .PP Characteristics of \fIList\fR mode: .IP "\(bu" 10 two empty lines indicate the end of data. .IP "\(bu" 10 An empty field (column) may be omitted, or may have a label, but no data. .IP "\(bu" 10 A long line can be continue by a null field (column): .Sp .Vb 2 \& Field2: blah blah blah \& : blah blah blah .Ve .IP "\(bu" 10 On a continuation, the null field is an arbitrary number of leading white space, a colon ':', a single blank or tab, followed by the continued text. .IP "\(bu" 10 Embedded newlines are indicated by the escape mechanism \*(L"\en\*(R". Similarly, embedded tabs are indicated with \*(L"\et\*(R", returns with \*(L"\er\*(R". .IP "\(bu" 10 If the \fI\f(CI@titles\fI\fR array is empty, the field names "\f(CW\*(C`Field_\*(C'\fR\fI\s-1NN\s0\fR" are used instead. .SH "ShowRow" .IX Header "ShowRow" Fetch rows successively from one or more columns of data. .PP   \fBShowRow\fR \fI\f(CI$rewindflag\fI\fR, \fI\e$index\fR, \fI\f(CI$col_array_1\fI\fR [, \fI\f(CI$col_array_2\fI\fR, ...;] .PP The \fBShowRow\fR subroutine returns a row of data from one or more columns of data. It is designed to be used as a \fIcallback\fR routine, within the \fBShowTable\fR routine. It can be used to select elements from one or more array reference arguments. .PP If passed two or more array references as arguments, elements of the arrays selected by \fI\f(CI$index\fI\fR are returned as the \*(L"row\*(R" of data. .PP If a single array argument is passed, and each element of the array is itself an array, the subarray is returned as the \*(L"row\*(R" of data. .PP If the \fI\f(CI$rewindflag\fI\fR flag is set, then the \fI\f(CI$index\fI\fR pointer is reset to zero, and \*(L"true\*(R" is returned (a scalar 1). This indicates that the data is rewindable to the \fBShowTable\fR routines. .PP When the \fI\f(CI$rewindflag\fI\fR is not set, then the current row of data, as determined by \fI\f(CI$index\fI\fR is returned, and \fI\f(CI$index\fI\fR will have been incremented. .PP An actual invocation (from \fBShowColumns\fR) is: .PP .Vb 3 \& ShowTable \e@titles, \e@types, \e@lengths, \& sub { &ShowRow( $_[0], \e$current_row, $col_names, $col_types, \& $col_lengths, \e@col_attrs); }; .Ve .PP In the example above, after each invocation, the \fI\f(CI$current_row\fI\fR argument will have been incremented. .SH "ShowTableValue" .IX Header "ShowTableValue" Prepare and return a formatted representation of a value. A value argument, using its corresponding type, effective width, and precision is formatted into a field of a given maximum width. .PP   \fI\f(CI$fmt\fI\fR = \fBShowTableValue\fR \fI\f(CI$value\fI\fR, \fI\f(CI$type\fI\fR, \fI\f(CI$max_width\fI\fR, \fI\f(CI$width\fI\fR, \fI\f(CI$precision\fI\fR, \fI\f(CI$showmode\fI\fR; .ie n .IP """width"" => \fI\f(CI$width\fI\fR" 10 .el .IP "\f(CWwidth\fR => \fI\f(CI$width\fI\fR" 10 .IX Item "width => $width" .PD 0 .IP "\fI\f(CI$width\fI\fR" 10 .IX Item "$width" .PD The width of the current value. If omittied, \fI\f(CI$max_width\fI\fR is assumed. .ie n .IP """precision"" => \fI\f(CI$precision\fI\fR" 10 .el .IP "\f(CWprecision\fR => \fI\f(CI$precision\fI\fR" 10 .IX Item "precision => $precision" .PD 0 .IP "\fI\f(CI$precision\fI\fR" 10 .IX Item "$precision" .PD The number of decimal digits; zero is assumed if omittied. .ie n .IP """value"" => \fI\f(CI$value\fI\fR" 10 .el .IP "\f(CWvalue\fR => \fI\f(CI$value\fI\fR" 10 .IX Item "value => $value" .PD 0 .IP "\fI\f(CI$value\fI\fR" 10 .IX Item "$value" .PD The value to be formatted. .IP "\fI\f(CI$type\fI\fR" 10 .IX Item "$type" The type name of the value; eg: \f(CW\*(C`char\*(C'\fR, \f(CW\*(C`varchar\*(C'\fR, \f(CW\*(C`int\*(C'\fR, etc. .ie n .IP """maxwidth"" => \fI\f(CI$max_width\fI\fR" 10 .el .IP "\f(CWmaxwidth\fR => \fI\f(CI$max_width\fI\fR" 10 .IX Item "maxwidth => $max_width" .PD 0 .IP "\fI\f(CI$max_width\fI\fR" 10 .IX Item "$max_width" .PD The maximum width of any value in the current value's column. If \fI\f(CI$width\fI\fR is zero or null, \fI\f(CI$max_width\fI\fR is used by default. \fI\f(CI$max_width\fI\fR is also used as a \fIminimum\fR width, in case \fI\f(CI$width\fI\fR is a smaller value. .IP "\fI\f(CI$width\fI\fR" 10 .IX Item "$width" The default width of the value, obtained from the width specification of the column in which this value occurs. .IP "\fI\f(CI$precision\fI\fR" 10 .IX Item "$precision" The precision specification, if any, from the column width specification. .IP "\fI\f(CI$showmode\fI\fR" 10 .IX Item "$showmode" The mode of the output: one of \*(L"table\*(R", \*(L"list\*(R", \*(L"box\*(R", or \*(L"html\*(R". Currently, only the \*(L"html\*(R" mode is significant: it is used to avoid using \s-1HTML\s0 tokens as part of the formatted text and length calculations. .SH "PlainText" .IX Header "PlainText"   \fI\f(CI$plaintext\fI\fR = \fB&PlainText\fR(\fI\f(CI$htmltext\fI\fR); .PP   \fB&PlainText\fR .PP This function removes any \s-1HTML\s0 formatting sequences from the input argument, or from \f(CW$_\fR if no argument is given. The resulting plain text is returned as the result. .SH "VARIABLES" .IX Header "VARIABLES" The following variables may be set by the user to affect the display (with the defaults enclosed in square brackets [..]): .IP "\fB\f(CB$Show_Mode\fB\fR [Box]" 10 .IX Item "$Show_Mode [Box]" This is the default display mode when using \fBShowTable\fR. The environment variable, \f(CW$ENV{\*(AqSHOW_MODE\*(Aq}\fR, is used when this variable is null or the empty string. The possible values for this variable are: \&\f(CW"Box"\fR, \f(CW"List"\fR, \f(CW"Table"\fR, and \f(CW"HTML"\fR. Case is insignificant. .IP "\fB\f(CB$List_Wrap_Margin\fB\fR [2]" 10 .IX Item "$List_Wrap_Margin [2]" This variable's value determines how large a margin to keep before wrarpping a long value's display in a column. This value is only used in \*(L"List\*(R" mode. .IP "\fB\f(CB$Max_List_Width\fB\fR [80]" 10 .IX Item "$Max_List_Width [80]" This variable, used in \*(L"List\*(R" mode, is used to determine how long an output line may be before wrapping it. The environment variable, \f(CW$ENV{\*(AqCOLUMNS\*(Aq}\fR, is used to define this value when it is null. .IP "\fB\f(CB$Max_Table_Width\fB\fR ['']" 10 .IX Item "$Max_Table_Width ['']" This variable, when set, causes all tables to have their columns scaled such that their total combined width does not exceed this value. When this variable is not set, which is the default case, there is no maximum table width, and no scaling will be done. .IP "\fB\f(CB$No_Escape\fB\fR ['']" 10 .IX Item "$No_Escape ['']" If set, allows embedded \s-1HTML\s0 text to be included in the data displayed in an HTML-formatted table. By default, the \s-1HTML\s0 formatting characters (\*(L"<\*(R", \*(L">\*(R", and \*(L"&\*(R") occuring in values are escaped. .IP "\fB\f(CB%URL_Keys\fB\fR" 10 .IX Item "%URL_Keys" In \s-1HTML\s0 mode, this variable is used to recognize which columns are to be displayed with a corresponding hypertext anchor. See \*(L"ShowHTMLTable\*(R" for more details. .IP "\fB\f(CB@HTML_Elements\fB\fR" 10 .IX Item "@HTML_Elements" An array of \s-1HTML\s0 elements (as of \s-1HTML 3.0\s0) used to recognize and strip for width calculations. .IP "\fB\f(CB$HTML_Elements\fB\fR" 10 .IX Item "$HTML_Elements" A regular expression string formed from the elements of \fB\f(CB@HTML_Elements\fB\fR. .SH "INTERNAL SUBROUTINES" .IX Header "INTERNAL SUBROUTINES" .SH "get_params" .IX Header "get_params"   my \fI\f(CI$args\fI\fR = \fB&get_params\fR \fI\e@argv\fR, \fI\e%params\fR, \fI\e@arglist\fR; .PP Given the \fI\f(CI@argv\fI\fR originally passed to the calling sub, and the hash of named parameters as \fI\f(CI%params\fI\fR, and the array of parameter names in the order expected for a pass-by-value invocation, set the values of each of the variables named in \fI\f(CI@vars\fI\fR. .PP If the only element of the \fI\f(CI@argv\fI\fR is a hash array, then set the variables to the values of their corresponding parameters used as keys to the hash array. If the parameter is not a key of the \fI\f(CI%params\fI\fR hash, and is not a key in the global hash \fB\f(CB%ShowTableParams\fB\fR, then an error is noted. .PP When \fI\f(CI@argv\fI\fR has multiple elements, or is not a hash array, set each variable, in the order given within \fI\f(CI@arglist\fI\fR, to the values from the \&\fI\f(CI@argv\fI\fR, setting the variables named by each value in \fI\f(CI%params\fI\fR. .PP Variables may given either by name or by reference. .PP The result is a \s-1HASH\s0 array reference, either corresponding directly to the \s-1HASH\s0 array passed as the single argument, or one created by associating the resulting variable values to the parameter names associated with the variable names. .SH "html_formats" .IX Header "html_formats"   (\fI\f(CI$prefixes\fI\fR,\fI\f(CI$suffixes\fI\fR) = \fBhtml_formats\fR \fI\e@html_formats\fR; .PP The \fBhtml_format\fR function takes an array reference of \s-1HTML\s0 formatting elements \fI\e@html_formats\fR, and builds two arrays of strings: the first: \&\fI\f(CI$prefixes\fI\fR, is an array of prefixes containing the corresponding \s-1HTML\s0 formatting elements from \fI\e@html_formats\fR, and the second, \&\fI\f(CI$suffixes\fI\fR, containing the appropriate \s-1HTML\s0 closing elements, in the opposite order. .PP The result is designed to be used as prefixes and suffixes for the corresponding titles and column values. .PP The array \fI\e@html_formats\fR contains lists of \s-1HTML\s0 formatting elements, one for each column (either title or data). Each array element is a list of one or more \s-1HTML\s0 elements, either given in \s-1HTML\s0 syntax, or as a \&\*(L"plain\*(R" name (ie: given as \f(CW\*(C`\e or plainly, \f(CW\*(C`ELEMENT\*(C'\fR). Multiple elements are separated by a comma \f(CW\*(Aq,\*(Aq\fR. .PP The resulting array of \fI\f(CI$prefixes\fI\fR contains the corresponding opening elements, in the order given, with the proper \s-1HTML\s0 element syntax. The resulting array of \fI\f(CI$suffixes\fI\fR contains the closing elements, in the opposite order given, with the proper \s-1HTML\s0 element syntax. .PP For example, if \fI\e@html_formats\fR contains the two elements: .PP .Vb 1 \& [ \*(AqFONT SIZE=+2,BOLD\*(Aq, \*(AqFONT COLOR=red,EM\*(Aq ] .Ve .PP then the resulting two arrays will be returned as: .PP .Vb 2 \& [ [ \*(Aq\*(Aq, \*(Aq\*(Aq ], \& [ \*(Aq\*(Aq, \*(Aq\*(Aq ] ] .Ve .SH "calc_widths" .IX Header "calc_widths"   (\fI\f(CI$num_cols\fI\fR, \fI\f(CI$widths\fI\fR, \fI\f(CI$precision\fI\fR, \fI\f(CI$max_widths\fI\fR) =   \fB&calc_widths\fR( \fI\f(CI$widthspec\fI\fR, \fI\f(CI$titles\fI\fR, \fI\f(CI$rewindable\fI\fR,       \fI\f(CI$row_sub\fI\fR, \fI\f(CI$fmt_sub\fI\fR, \fI\f(CI$types\fI\fR, \fI\f(CI$showmode\fI\fR,       \fI\f(CI$max_width\fI\fR); .SS "\fB\s-1DESCRIPTION\s0\fP" .IX Subsection "DESCRIPTION" \&\fBcalc_widths\fR is a generalized subroutine used by all the \fBShowTable\fR variant subroutines to setup internal variables prior to formatting for display. \fBCalc_widths\fR handles the column width and precision analysis, including scanning the data (if rewindable) for appropriate default values. .PP The number of columns in the data is returned, as well as three arrays: the declared column widths, the column precision values, and the maximum column widths. .SS "\fB\s-1RETURN VALUES\s0\fP" .IX Subsection "RETURN VALUES" .IP "\fI\f(CI$num_cols\fI\fR" 10 .IX Item "$num_cols" is the number of columns in the data. If the data is not rewindable, this is computed as the maximum of the number of elements in the \&\fI\f(CI$widthspec\fI\fR array and the number of elements in the \fI\f(CI$titles\fI\fR array. When the data is rewindable, this is the maximum of the number of columns of each row of data. .IP "\fI\f(CI$widths\fI\fR" 10 .IX Item "$widths" is the column widths array ref, without the precision specs (if any). Each column's width value is determined by the original \fI\f(CI$widthspec\fI\fR value and/or the maximum length of the formatted data for the column. .IP "\fI\f(CI$precision\fI\fR" 10 .IX Item "$precision" is the precision component (if any) of the original \fI\f(CI$widthspec\fI\fR array ref. If there was no original precision component from the \fI\f(CI$widthspec\fI\fR, and the data is rewindable, then the data is examined to determine the maximum default precision. .IP "\fI\f(CI$max_widths\fI\fR" 10 .IX Item "$max_widths" is the ref to the array of maximum widths for the given columns. .SS "\fB\s-1ARGUMENTS\s0\fP" .IX Subsection "ARGUMENTS" .IP "\fI\f(CI$widthspec\fI\fR" 10 .IX Item "$widthspec" A reference to an array of column width (or length) values, each given as an integer, real number, or a string value of "\fIwidth\fR.\fIprecision\fR". If a value is zero or null, the length of the corresponding formatted data (if rewindable) and column title length are used to determine a reasonable default. .Sp If a column's \fIwidth\fR portion is a positive, non-zero number, then the column will be this wide, regardless of the values lengths of the data in the column. .Sp If the column's \fIwidth\fR portion is given as a negative number, then the positive value is used as a minimum column width, with no limit on the maximum column width. In other words, the column will be at least \&\fIwidth\fR characters wide. .Sp If the data is not rewindable, and a column's width value is null or zero, then the length of the column title is used. This may cause severe wrapping of data in the column, if the column data lengths are much greater than the column title widths. .IP "\fI\f(CI$titles\fI\fR" 10 .IX Item "$titles" The array ref to the column titles; used to determine the minimum acceptable width, as well as the default number of columns. If the \&\f(CW$titles\fR array is empty, then the \f(CW$widthspec\fR array is used to determine the default number of columns. .IP "\fI\f(CI$rewindable\fI\fR" 10 .IX Item "$rewindable" A flag indicating whether or not the data being formatted is rewindable. If this is true, a pass over the data will be done in order to calculate the maximum lengths of the actual formatted data, using \fI\f(CI$fmt_sub\fI\fR (below), rather than just rely on the declared column lengths. This allows for optimal column width adjustments (ie: the actual column widths may be less than the declared column widths). .Sp If it is not desired to have the column widths dynamically adjusted, then set the \fI\f(CI$rewindable\fI\fR argument to 0, even if the data is rewindable. .IP "\fI\f(CI$row_sub\fI\fR" 10 .IX Item "$row_sub" The code reference to the subroutine which returns the data; invoked only if \fI\f(CI$rewindable\fI\fR is non-null. .IP "\fI\f(CI$fmt_sub\fI\fR" 10 .IX Item "$fmt_sub" The subroutine used to determine the length of the data when formatted; if this is omitted or null, the length of the data is used by default. The \fI\f(CI$fmt_sub\fI\fR is used only when the data is rewindable. .IP "\fI\f(CI$types\fI\fR" 10 .IX Item "$types" An array reference to the types of each of the value columns; used only when \fI\f(CI$fmt_sub\fI\fR is invoked. .IP "\fI\f(CI$showmode\fI\fR" 10 .IX Item "$showmode" A string indicating the mode of the eventual display; one of four strings: "\f(CW\*(C`box\*(C'\fR\*(L", \*(R"\f(CW\*(C`table\*(C'\fR\*(L", \*(R"\f(CW\*(C`list\*(C'\fR\*(L", and \*(R"\f(CW\*(C`html\*(C'\fR". Used to adjust widths for formatting requirements. .IP "\fI\f(CI$max_width\fI\fR" 10 .IX Item "$max_width" The maximum width of the table being formatted. If set, and the total sum of the individual columns exceeds this value, the column widths are scaled down uniformly. If not set (null), no column width scaling is done. .SH "putcell" .IX Header "putcell"   \fI\f(CI$wrapped\fI\fR = \fB&putcell\fR( \fI\e@cells\fR, \fI\f(CI$c\fI\fR, \fI\f(CI$cell_width\fI\fR, \fI\e@prefix\fR, \fI\e@suffix\fR, \fI\f(CI$wrap_flag\fI\fR ); .PP Output the contents of an array cell at \fI\f(CI$cell\fI\fR[\fI\f(CI$c\fI\fR], causing text longer than \fI\f(CI$cell_width\fI\fR to be saved for output on subsequent calls. Prefixing the output of each cell's value is a string from the two-element array \fI\f(CI@prefix\fI\fR. Suffixing each cell's value is a string from the two-element array \fI\f(CI@suffix\fI\fR. The first element of either array is selected when \fI\f(CI$wrap_flag\fI\fR is zero or null, or when there is no more text in the current to be output. The second element is selected when \fI\f(CI$wrap_flag\fI\fR is non-zero, and when there is more text in the current cell to be output. .PP In the case of text longer than \fI\f(CI$cell_width\fI\fR, a non-zero value is returned. .PP Cells with undefined data are not output, nor are the prefix or suffix strings. .SH "center" .IX Header "center" Center a string within a given width. .PP   \fI\f(CI$field\fI\fR = \fBcenter\fR \fI\f(CI$string\fI\fR, \fI\f(CI$width\fI\fR; .SH "max" .IX Header "max" Compute the maximum value from a list of values. .PP   \fI\f(CI$max\fI\fR = \fB&max\fR( \fI\f(CI@values\fI\fR ); .SH "min" .IX Header "min" Compute the minum value from a list of values. .PP   \fI\f(CI$min\fI\fR = \fB&min\fR( \fI\f(CI@values\fI\fR ); .SH "max_length" .IX Header "max_length" Compute the maximum length of a set of strings in an array reference. .PP   \fI\f(CI$maxlength\fI\fR = \fB&max_length\fR( \fI\e@array_ref\fR ); .SH "htmltext" .IX Header "htmltext" Translate regular text for output into an \s-1HTML\s0 document. This means certain characters, such as \*(L"&\*(R", \*(L">\*(R", and \*(L"<\*(R" must be escaped. .PP   \fI\f(CI$output\fI\fR = \fB&htmltext\fR( \fI\f(CI$input\fI\fR [, \fI\f(CI$allflag\fI\fR ] ); .PP If \fI\f(CI$allflag\fI\fR is non-zero, then all characters are escaped. Normally, only the four \s-1HTML\s0 syntactic break characters are escaped. .SH "out" .IX Header "out" Print text followed by a newline. .PP   \fBout\fR \fI\f(CI$fmt\fI\fR [, \fI\f(CI@text\fI\fR ]; .SH "put" .IX Header "put" Print text (without a trailing newline). .PP   \fBout\fR \fI\f(CI$fmt\fI\fR [, \fI\f(CI@text\fI\fR ]; .SH "AUTHOR" .IX Header "AUTHOR" Alan K. Stebbens .SH "BUGS" .IX Header "BUGS" .IP "\(bu" 10 Embedded \s-1HTML\s0 is how the user can insert formatting overrides. However, the \s-1HTML\s0 formatting techniques have not been given much consideration \*(-- feel free to provide constructive feedback.