GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Extra(3) User Contributed Perl Documentation Extra(3)

Text::FixedLength::Extra - various niceties for Text::FixedLength lovers.

  use Text::FixedLength::Extra; #automatically uses Text::FixedLength

  my %format        =   (record_type => '3L', total_orders => '5R');
  my @field_order   = qw(record_type total_orders);
  my %data          =   (record_type => 'F',  total_orders => 300);

  # Bonus One: Simplified API to Text::FixedLength !
  $x = fixedlength(\%format, \%data, \@field_order);

  # Bonus Two: Zero filling and processing of integers and floating points ! 
  my %format        =   (record_type => '3R', total_orders => '10R*F3');
  my @field_order   = qw(record_type total_orders);
  my %data          =   (record_type => 'F',  total_orders => 300.52894);


  $x = fixedlength(\%format, \%data, \@field_order);

Right now, Text::FixedLength::Extra does two things for those who like using Text::FixedLength - simpler API and extended number processing.

A function, fixedlength() has been created which should make it easier to create fixed-width reports. Here is a sample of setting up data for use with fixedlength:

  # the fields we will format and their formatting instructions
  my %format = 
    (
     record_type => '3',
     upc => '13L',
     lcc_label => '5R',
     lcc_catalog => '7R',
     lcc_config => '1',
     artist_name => '30L',
     item_title => '30L',
     quoted_price => '6R',
     quantity => '4R',
     customer_title => '30L',
     customer_reference => '20L'
    );

  # how to order the fields in %format
  my @format =  qw(record_type   upc     lcc_label     lcc_catalog     
lcc_config     artist_name     item_title     quoted_price     quantity  
customer_title     customer_reference    );
  

  my %data = ( record_type => '23423' ... customer_reference => 'adfja;kdf');

  my $formatted_line = fixedlength(\%format, %data, \@format);

The standard format instruction with Text::FixedLength is

  WIDTH JUSTIFICATION?

E.g. 6L creates a left-justified field taking up 6 spaces, filling any non-used spaces with a spaces.

This module re-implements the Text::FixedLength::getFixed function to handle additional optional syntax for formatting numbers. The new format instruction is:

  WIDTH JUSTIFICATION? (ZERO_FILL? D)?
    or
  WIDTH JUSTIFICATION? (ZERO_FILL? F PLACES_AFTER_DECIMAL)?

If you dont understand the above let me give you a nice set of examples:

  10R*F3 means uses 10 spaces, zero fill if necessary and allow 3 places after the decimal point.

  10R*D  means uses 10 spaces, zero fill if necessary.

  10RF3  means uses 10 spaces, space fill (not zero-fill, note there was no * in the specification) if necessary and allow 3 places after the decimal point.

fixedlength()

Text::FixedLength::getFixed()

T. M. Brannon, <TBONE@CPAN.ORG>

perl(1). Parse::FixedLength
2022-04-08 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.