Data::Display

Perl extension for formating and displaying array
Download

Data::Display Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Geo Tiger
  • Publisher web site:
  • http://search.cpan.org/~geotiger/

Data::Display Tags


Data::Display Description

Perl extension for formating and displaying array Data::Display is a Perl module that will scan through each records and fields in the array to collect information about the content in the array. It creates a column definition array, builds formating strings, and display the contents nicely.The column definition array built by the module is actually an array with hash members. It contains these hash elements ('col', 'typ', 'max', 'min', 'dec', 'req' and 'dsp') for each column. The subscripts in the array are in the format of $ary{$hash_ele}. The hash elements are: col - column name typ - column type, 'N' for numeric, 'C' for characters, and 'D' for date max - maximum length of the records in the column (could use 'wid' to record the max length of the records.) min - minimum length of the record in the column (When 'wid' is used, no 'min' is needed.) dft - date format such as YYYY/MM/DD, MON/DD/YYYY, etc. dec - maximun decimal length of the record in the column req - whether there is null or zero length records in the column only 'NOT NULL is shown dsp - description of the columnsThe array passed to the module can have the first row containing column names or have a separate array containing column definitions. It has to be in the same format of the array that we describe in the above if it is referenced to a out side array.It also creates and tracks a format information. The format information contains in a separate array, which has exactly the same element as the column definition array.It has many "set" and "get" methods to assign and to query data contained in the object. Here is the list of methods:the constructor new($drf, $crf, $ech, %arg) Without any input, i.e., new(), the constructor generates an empty object. If any argument is provided, the constructor expects them in the right order.skip_first_row/set_first_row(1) This method indicates that the first row in the array contains column names. The default is false.get_skip_first_row/get_first_row This method checks the indicator for the first row data, i.e., whether it contains column names.set_field_sep($ech)/get_field_sep This method sets/gets output field separator. The default separator is a space(" ").set_data_ref($drf)/get_data_ref This method sets/gets data array reference. The records in the array that the ref points to are used to determine column definitions and to be displayed.set_cols_ref($crf)/get_cols_ref This method sets/gets column array reference. The array contains column name, column type, column max length, column min length, column decimal length, and column constraints.get_column_defs_arrayref($drf, $ech) This method gets the reference pointing to the column definition array. If new data array reference is specified, it gets the definition for the data array. It does not change the internal attributes defined for the object, so you can pass any data array reference to this method without touching the internal attributes in the object. Actually, all the get methods do not change anything in the object.get_column_defs($drf, $ech) This method get the contents in the column definition array. If no input column array ref and no column names in the first row, it generates sequential column names such as "FLD001", "FLD002, etc. If $ech is specified, it will display the content of the column definition array.disp_col_defs($crf) This method displays the content of column definition array in a nice format.set_col_width/get_col_width($cp,$v1,$cn,$v2,...) This method sets/gets the max length of columns based on column position ($cp) or column names ($cn). The column position is zero based. The default is the same as the column definition array. The get method without any argument returns the Perl format string based on modified column max width. If no modification, the returned format string is the same as that from get_format_ string.get_format_string($crf,$sep,$ech) This method gets the Perl format string. It is created based on the column format array.get_content($drf,$crt,$typ,$ech) This method gets the formated contents from the data array. It uses the separator to divide fields. If $drf and $crf are not provided, this method will get them from the attributes in the object. The $typ sepcifies what type of output format will be, currently only "text" is available. If $ech is specified, the content will also be displayed.get_no_of_fields/get_no_of_columns This method gets number of fields (columns) in the data array.get_no_of_rows/get_no_of_records This method gets number of rows (records) in the data array.get_dimension($drf) This method gets number of rows and columns in the data array or the array ref passed to this method.add_col_def($fld, $col_def) This method add or construct column definition array. You can either append to the end of the column def array or insert into the position that you specified. It takes two inputs: column name or index and column definitions. If column name is specified in the first input, it will try to append the column and its defintion to the end of the array. If the first input is the column position, then it inserts the definiton after the position specified. You can use two format to define column, i.e., camma delimited values or comma delimited hash assignment. In camma delimited value format, the vlaues have to be in the exact order in 'col:typ:max:min:dec:dft:req'. In hash assignment format, order is not an issue. For instance, 'max=>5:typ=D:dft=>YYYY/MM/DD'. The column name or column index are checked before any insertion is commited. You can add as many columns as you like in one run, just be cautious when you insert columns. You may not get the position that you desire since array's index changes once you have inserted column definiton in it.mod_col_def($fld, $col_def) This method modifies the existing column definitons in the column definiton array. You can use the same ways and formats described in the add_col_def method.SYNOPSIS use Data::Display; $dsp = Data::Display->new($drf, $crf, $ech, %arg); $dsp->skip_first_row; # i,e. 1st row contains col names $dsp->set_skip_first_row(1); # is the same as the above $dsp->set_field_sep($ech); # default is a space $dsp->set_data_ref($drf); # ref to an array containing data $dsp->set_cols_ref($crf); # ref to an array containing col defs $dsp->set_col_width($fld,$wd,$col,$wd,...); $dsp->add_col_def($col,'typ:max:min:dec:dft:req'); # append $dsp->add_col_def($idx,'col:typ:max:min:dec:dft:req'); # isert $dsp->mod_col_def($fld,'typ:max:min:dec:dft:req'); $rc = $dsp->get_skip_first_row; $rc = $dsp->get_first_row; # the same as the above $ary_ref = $dsp->get_column_defs_arrayref($drf,$ech); @ary = $dsp->get_column_defs(\@ary,$ech); # $yn: display? $str = $dsp->get_col_width(); # get format string @ary = $dsp->get_col_width($fld,$col,...); # a list of width ($cfs, $dfs) = $dsp->get_col_width(); ($cfs, $dfs) = $dsp->get_format_string($crf,$sep,$ech); $str = $dsp->get_content($drf,$crf,$typ,$ech); $str = $dsp->get_content($typ,$ech); # use ary refs $rv = $dsp->get_no_of_fields; $rv = $dsp->get_no_of_columns; $rv = $dsp->get_no_of_rows; $rv = $dsp->get_no_of_records; ($rows, $cols) = $dsp->get_dimension($drf); ($rows, $cols) = $dsp->get_dimension; Notation and Conventions $dsp a display object $drf data array reference $crf column definition array reference $ech whether to echo messages or contents $cfs column heading format string $dfs data content format string $sep field separator character $typ output type, text, html, etc. $drh Driver handle object (rarely seen or used in applications) $h Any of the $??h handle types above $rc General Return Code (boolean: true=ok, false=error) $rv General Return Value (typically an integer) @ary List of values returned from the database, typically a row of data $rows Number of rows processed (if available, else -1) $fh A filehandle undef NULL values are represented by undefined values in perl \%attr Reference to a hash of attribute values passed to methods Requirements: · Perl


Data::Display Related Software