package PM::FixedWidthFile; use strict; use warnings; use autodie; use Exporter qw{import}; our @EXPORT_OK = qw{populate_file}; use Carp; sub populate_file { my ($fh, $record_length, $field_data) = @_; for my $fields (@$field_data) { my $line = pack 'A' . $record_length; my $offset = 0; _add_field(\$line, \$offset, @$_) for @$fields; print {$fh} $line, "\n"; } return; } sub _add_field { my ($line_ref, $offset_ref, $length, $data, $r_align) = @_; if ($length < length $data) { croak "Data [$data] too large for field of length [$length]"; } my @dat_pad = ($data, ' ' x ($length - length $data)); substr($$line_ref, $$offset_ref, $length) = join '' => @dat_pad[$r_align ? (1, 0) : (0, 1)]; $$offset_ref += $length; return; } 1; =head1 NAME PM::FixedWidthFile - TODO (for Jake): module documentation in POD format