Tree::Numbered::Tools

Perl module to create tree objects using different sources
Download

Tree::Numbered::Tools Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Johan Kuuse
  • Publisher web site:
  • http://search.cpan.org/~kuuse/

Tree::Numbered::Tools Tags


Tree::Numbered::Tools Description

Perl module to create tree objects using different sources Tree::Numbered::Tools is a child Perl class of the Tree::Numbered module. Its purpouse is to easily create a tree object from different sources.The most useful source is probably a text file (see SYNOPSIS, example 1). The text file visualizes the tree structure as well as node names in the first column. Any other columns represent each node's properties. The format is easy to read and understand, even for a non-programmer. Besides, editing a text file is normally far more easy than editing records in a database table. Anyhow, at run time, reading from/writing to a database outperformances a text file. This module is intented to be used as a tool to create database tables using text files, not to replace tables with text files (even if the module permits you to use the text file as a source without dealing with a database). The format of the first column in the text file only requires that each tree level should be indented using one or more spaces (or tabs). It is recommended to be consistent and use the same number of spaces to indent all tree levels, even if the readFile() method tries to determine each node's level even if the indenting isn't consistent. To get each node's properties, the readFile() method parses each line in the text file using the Text::ParseWords module, so any property value containg a space must be quoted. If the last column or columns in the text file for a node are omitted, the corresponding property value is assigned the empty string.Programmers who prefer not using an external source when creating a tree may use an array reference. Being a programmer, it is probably easier to edit an array than database records. See SYNOPSIS, example 2.The purpouse of the SQL statement as a source for the tree object is the more straightforward way to map column names using Tree::Numbered::Tools->readSQL() than the Tree::Numbered::DB->read() method. See SYNOPSIS, example 3.SYNOPSISExample 1: Using a text file as a source: Value LastName FirstName# ----- -------- --------- Grandfather Smith Abraham Son1 Smith Bert Son2 Smith 'Clumsy Carl' Grandson1 Jones Dennis Grandson2 Jones Eric Son3 Smith 'Fatty Fred' Grandson3 Smith Greg Grandson4 Smith Huey Grandmother Smith Anna Daughter1 Smith Berta Daughter2 Smith Celine use Tree::Numbered::Tools; # Reads a text file, returns a tree object my $tree = Tree::Numbered::Tools->readFile( filename => $filename, use_column_names => 1, );Example 2: Using an array as a source: use Tree::Numbered::Tools; my $arrayref = , , , , , ]; my $tree = Tree::Numbered::Tools->readArray( arrayref => $arrayref, use_column_names => 1, );Example 3: Using a database table as a source, use the SQL 'AS' statement for easy column mapping: use Tree::Numbered::Tools; my $sql = 'SELECT serial, parent AS "Parent", name AS "Name", url AS "URL" FROM mytable ORDER BY serial'; my $tree = Tree::Numbered::Tools->readSQL( dbh => $dbh, sql => $sql, );Example 4: Display a tree object in the same format as the text file in example 1: my $output = Tree::Numbered::Tools->outputFile();Example 5: Display a tree object as an array reference, to be used for cut 'n paste in a Perl program. my $output = Tree::Numbered::Tools->outputArray();Example 6: Convert a text file to a database table. my $sql = Tree::Numbered::Tools->convertFile2DB( filename => $filename, use_column_names => 1, dbh => $dbh, table => $table, );Example 7: Convert a text file to SQL 'INSERT INTO' statements. my $sql = Tree::Numbered::Tools->convertFile2SQL( filename => $filename, use_column_names => 1, ); Requirements: · Perl


Tree::Numbered::Tools Related Software