Dion Almaer > Text-FixedLength-0.12 > Text::FixedLength

Download:
Text-FixedLength-0.12.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.12   Source  

NAME ^

Text::FixedLength - Parse and create fixed length field records

SYNOPSIS ^

  use Text::FixedLength;

  # -- get fixed length records from delimited text
  my @fL = qw(4L 4L 4L 4L); # -- left justified (which is default)
  my @fR = qw(4R 4R 4R 4R); # -- right justified (not default)
  my $str= join "\t", qw(1 2 3 4);
  my @a1 = delim2fixed([ $str ],"\t", \@fL);
  my @a2 = delim2fixed([ $str ],"\t", \@fR);
  # -- $a1[0] would now hold: '1   2   3   4   '
  # -- $a2[0] would now hold: '   1   2   3   4'

  # -- get delimited text from fixed length
  my @a1 = fixed2delim([ '2233344441' ], [qw(2 3 4 1)], ':');
  # -- $a1[0] would now hold: 22:333:4444:1

DESCRIPTION ^

Text::FixedLength was made to be able to manipulate fixed length field records. You can manipulate arrays of data, or files of data. This module allows you to change between delimited and fixed length records.

E.g. DELIM (with ':' as the delim) aaa:bbb:ccccc:dddddd FIXED 'dion almaer mn55446' where the format is left justified: 8 9 2 5 (SEE FORMATS)

FORMATS ^

  You need to be familiar with the format array references used
  to create, and parse fixed length fields.
  The array reference holds the length of the field, and optionally
  holds either 'L' for left justified, or 'R' for right justified.
  By default fields are left justified (but you can change this
  default via the setJustify(L || R) functino)

  For example if you had the following fixed length record:

  1234567890123456789012345 <- place holder
  dion    almaer    mn55446

  The format (if all left justified) would be:
  $format = [ 8, 10, 2, 5 ];

FUNCTIONS ^

o delim2fixed($filename | $dataAREF, $delim, $formatAREF,[$outfilename])

  delim2fixed returns fixed length field records from delimited records

  ARGUMENTS:
  1: Filename or an array reference holding delimited strings
  2: Delimiter for the data in arg 1
  3: Format array reference of the fixed lengths (see FORMATS)
  4: [OPTIONAL] Filename to write the fixed length data too

  RETURNS: Depending on wantarray it will return either an array of
           fixed length records, an array reference, or nothing
  e.g. @array = delim2fixed('file',':',[ qw(2 2 4 10) ]);
       $scalar = delim2fixed([ 'foo:bar:whee' ],':',[ qw(5 5 5) ]);
       delim2fixed('file',"\t",[ qw(6 10 4 1) ], 'outputfile');

o fixed2delim($filename | $dataAREF, $formatAREF, $delim, [$outfilename])

  fixed2delim returns delimited records from fixed length records

  ARGUMENTS:
  1. Filename or an array reference holding fixed length records
  2. Format array reference for the data in arg 1
  3. Delimiter for the output data
  4: [OPTIONAL] Filename to write the delimited data too

  RETURNS: Depending on wantarray it will return either an array of
           delimited records, an array reference, or nothing
  e.g. @array = fixed2delim('file',[ qw(2 2 4 10) ],':');
       $scalar = fixed2delim([ 'foo   bar whee' ],':',[ qw(6 4 4) ]);
       fixed2delim('file',[ qw(6 10 4 1) ],"\t",'outputfile');

  NOTE: The resulting strings are cleaned of whitespace at the
        beginning and the end. So '  foo  ' becomes 'foo'
        You do not need to worry about the justification of the
        text as the whitespace is cleaned 

o setJustify($justchar) [either 'L' or 'R'] [default: L]

  setJustify sets the default justification (originally set to left).
  
  ARGUMENTS: either L for left justified, or R for right justified

o setCrop($bool) [either 1 or 0] [default: 1]

  setCrop sets whether records should be cropped to the size of the format
  or not.

  For example if you have a string 'whee' that is meant to be fit into
  a fixed format of 2 then if setCrop is true the record will be changed
  to 'wh' to constrain it
syntax highlighting: