altoc

Section: Misc. Reference Manual Pages (1)
Updated: Oct 2001

NAME

altoc - generate templated output from CVS input

SYNOPSIS

altoc [options]

DESCRIPTION

altoc can generate formatted output from CVS input using a template. The tool is mainly a combination of the two Perl modules Text::CSV_XS(3) and Text::Template(3).

Options

Below is a summary of all options that altoc accepts. Most options have two equivalent names, one of which is a single letter preceded by -, and the other of which is a long name preceded by --.
General options:
-i file

--input file
Input file. Defaults to STDIN.
-o file

--output file
Output file. Defaults to STDOUT.
-t file

--template file
The template file for the output. See TEMPLATES below. If no template is given, a HTML table is generated from the input data.
CVS options (format of input data):
-q char

--quote-char char
The char used for quoting fields containing blanks, by default the double quote character (`"').
-schar

--sep-char char
The char used for separating fields, by default a comma. (`,')
-b

--[no]binary
If this option is enabled, you may use binary characters in quoted fields, including lines feeds, carriage returns and NUL bytes. (The latter must be escaped as `"0'.) By default this feature is off.
Template options:
--delim-open string

--delim-close string
Allows you to change the delimiter which separates the script from the text in your template. This defaults to `{' for the open delimiter and to `}' for the closing delimiter.
With this setting it is possible to create ASP/JSP/PHP/whatever-like templates. Use the following command line for an ASP-like template:
altoc --delim-open <% --delim-close %>
Of course the template code still needs to be plain Perl. (See TEMPLATES below)
-r

--repeat
This option applies the whole template for each input record. This is useful to simplify your templates. (See TEMPLATES below)

TEMPLATES

altoc has support for templates. It uses the CPAN module Text::Template(3) for this. I'll give you only a quick overview here, because you can find all the details in the man page for Text::Template(3).
The templates contain embedded Perl code. To embed Perl code you open a script section with { and close it with }. This delimiters can be changed using the command line parameters delim-open and delim-close. (See Options below)
The data input is available in the LoL (list of lists) variable @CSV. So for example to get the second column of the third row you can use the statement:
{ $CSV[2][1] }
(Indexes are 0-based)
You may be more interested in printing every row of your input. To achieve this you can use something like this code: (In fact this is about the code used when you don't specify a template)

<table>
{
  for $row (@CSV) {
    $OUT .= "<tr>\n";
    for $col (@$row) {
      $OUT .= "<td>$col</td>\n";
    }
    $OUT .= "</tr>\n";
  }
}
</table>
If you have the repeat command line option set, the whole template is repeated for every input line and the current input line is stored in the list variable @ROW. This is nice to simplify your template. If you need to repeat your full template you have one big loop and then the template doesn't really simplify your life, does it?
Example for a letter:

Subject: { $ROW[1] }
Dear { $ROW[0] },
Profit now with our new product. It will simplify your life a lot!

BUGS

There aren't any known bugs at the moment.

AUTHOR

Patrice Neff <software@patrice.ch>.
http://www.patrice.ch/en/computer/programs/altoc/altoc.html

SEE ALSO

Text::CSV_XS(3), Text::Template(3), perl(1)
This document was created by man2html, using the manual pages.
Time: 12:10:09 GMT, October 12, 2001