Name
Data::Table::Text - Write data in tabular text format
Synopsis
use Data::Table::Text;
say STDERR formatTable([
[".", "aa", "bb", "cc"],
[1, "A", "B", "C"],
[2, "AA", "BB", "CC"],
[3, "AAA", "BBB", "CCC"],
[4, 1, 22, 333]]);
# . aa bb cc
# 1 1 A B C
# 2 2 AA BB CC
# 3 3 AAA BBB CCC
# 4 4 1 22 333
say STDERR formatTable([
{ aa => "A", bb => "B", cc => "C" },
{ aa => "AA", bb => "BB", cc => "CC" },
{ aa => "AAA", bb => "BBB", cc => "CCC" },
{ aa => 1, bb => 22, cc => 333 }]);
# aa bb cc
# 1 A B C
# 2 AA BB CC
# 3 AAA BBB CCC
# 4 1 22 333
say STDERR formatTable({
"" => ["aa", "bb", "cc"],
"1" => ["A", "B", "C"],
"22" => ["AA", "BB", "CC"],
"333" => ["AAA", "BBB", "CCC"],
"4444" => [1, 22, 333]});
# aa bb cc
# 1 A B C
# 22 AA BB CC
# 333 AAA BBB CCC
# 4444 1 22 333
say STDERR formatTable({
a => { aa => "A", bb => "B", cc => "C" },
aa => { aa => "AA", bb => "BB", cc => "CC" },
aaa => { aa => "AAA", bb => "BBB", cc => "CCC" },
aaaa => { aa => 1, bb => 22, cc => 333 }});
# aa bb cc
# a A B C
# aa AA BB CC
# aaa AAA BBB CCC
# aaaa 1 22 333
say STDERR formatTable(["a", "bb", "ccc", 4444]);
# 0 a
# 1 bb
# 2 ccc
# 3 4444
say STDERR formatTable({ aa => "A", bb => "B", cc => "C" });
# aa A
# bb B
# cc C
Description
Time stamps
Date and timestamps as used in logs
dateTimeStamp
Year-monthNumber-day at hours:minute:seconds
dateStamp
Year-monthName-day
timeStamp
hours:minute:seconds
xxx
Execute a command checking and logging the results with a time stamp
1 {my @cmd = @_; Command to execute in phrases
Files and paths
Operations on files and paths
fileSize
Get the size of a file
1 $file File name
fileModTime
Get the modified time of a file in seconds since epoch
1 $file File name
fileOutOfDate
Check whether a target is out of date relative to an array of files. Used when one file is dependent on many files to make sure that the target is younger than all its sources. Allows for an easy test of the
1 $target Target
2 @sources Sources
Example:
... if fileOutOfDate($target, $source1, $source2, $source3)
as in 'make' to decide whether the target needs to be updated from its sources. Returns the first out of date source file to make debugging easier, or undef if no files are out of date.
filePath
Create a file path from an array of file name components
1 @file File components
filePathDir
Directory from an array of file name components
1 @file File components
filePathExt
File name from file name components and extension
1 @file File components and extension
quoteFile
Quote a file name
1 $file File name
currentDirectory
Get the current working directory
currentDirectoryAbove
The path to the folder above the current working folder
parseFileName
Parse a file name into (path, name, extension)
1 $file File name to parse
containingFolder
Path to the folder that contains this file, or use "parseFileName"
1 $file File name
Find files and folders
Find files and folders below a folder
findFiles
Find all the file under a folder
1 $dir Folder to start the search with
findDirs
Find all the folders under a folder
1 $dir Folder to start the search with
fileList
File list
1 $pattern Search pattern
Read and write files
Read and write strings from files creating paths as needed
readFile
Read file
1 $file File to read
readBinaryFile
Read binary file - a file whose contents are not to be interpreted as unicode
1 $file File to read
makePath
Make a path for a file name or a folder
1 $path Path
writeFile
Write a string to a file after creating a path to the file if necessary
1 $file File to write to
2 $string String to write
appendFile
Append a string to a file after creating a path to the file if necessary
1 $file File to append to
2 $string String to write
writeBinaryFile
Write a string to a file in binmode after creating a path to the file if necessary
1 $file File to write to
2 $string String to write
Images
Image operations
imageSize
Return (width, height) of an image obtained via imagemagick
1 $image File containing image
convertImageToJpx
Convert an image to jpx format
1 $source Source file
2 $target Target folder (as multiple files will be created)
3 $size Size of each tile
Powers
Power
powerOfTwo
Test whether a number is a power of two, return the power if it is else undef
1 $n Number to check
containingPowerOfTwo
Find log two of the lowest power of two greater than or equal to a number
1 $n Number to check
Format
Format data structures as tables
formatTableBasic
Tabularize text - basic version
1 $data Data to be formatted
2 $separator Optional line separator
formatTable
Format various data structures
1 $data Data to be formatted
2 $title Optional title
3 $separator Optional line separator
keyCount
Count keys down to the specified level
1 $maxDepth Maximum depth to count to
2 $ref Reference to an array or a hash
Lines
Load data structures from lines
loadArrayFromLines
Load an array from lines of text in a string
1 $string The string of lines from which to create an array
loadHashFromLines
Load a hash: first word of each line is the key and the rest is the value
1 $string The string of lines from which to create a hash
loadArrayArrayFromLines
Load an array of arrays from lines of text: each line is an array of words
1 $string The string of lines from which to create an array of arrays
loadHashArrayFromLines
Load a hash of arrays from lines of text: the first word of each line is the key, the remaining words are the array contents
1 $string The string of lines from which to create a hash of arrays
checkKeys
Check the keys in a hash
1 $test The hash to test
2 $permitted The permitted keys and their meanings
LVALUE methods
Object oriented methods using LVALUE methods
genLValueScalarMethods
Generate LVALUE scalar methods
1 @names Method names
genLValueScalarMethodsWithDefaultValues
Generate LVALUE scalar methods with default values
1 @names Method names
genLValueArrayMethods
Generate LVALUE array methods
1 @names Method names
genLValueHashMethods
Generate LVALUE hash methods
1 @names Method names
Strings
Actions on strings
indentString
Indent lines contained in a string or formatted table by the specified amount
1 $string The string of lines to indent
2 $indent The indenting string
trim
Trim off white space from from front and end of string
1 $string String
pad
Pad a string with blanks to a multiple of a specified length
1 $string String
2 $length Tab width
nws
Normalize white space in a string to make comparisons easier
1 $string String to normalize
javaPackage
Extract package name from java file
1 $javaFile Java file
extractDocumentation()
Extract documentation from a perl script between lines marked with \A#n and \A# as illustrated just above this line - sections are marked with #n, sub name and parameters are on two lines, private methods are marked with ##
Index
genLValueScalarMethodsWithDefaultValues
Installation
This module is written in 100% Pure Perl and is thus easy to read, use, modify and install.
Standard Module::Build process for building and installing modules:
perl Build.PL
./Build
./Build test
./Build install
Author
philiprbrenan@gmail.com
http://www.appaapps.com
Copyright
Copyright (c) 2016-2017 Philip R Brenan.
This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.