I had a similar situation where I had a fixed length file generated on
a mainframe. I actually used this to do some edits and inserted rows
into an Oracle database, but I've shortened it a bit here and used
joining the record with a "pipe":
#!/usr/bin/perl
use strict;
my @record_layout = qw(
state_code
place_code
state_alpha_code
class_code
place_name
county_code
county_name
zip_code
);
my %field_types = (
state_code => 'A2',
place_code => 'A5',
state_alpha_code => 'A2',
class_code => 'A2',
place_name => 'A52',
county_code => 'A3',
county_name => 'A22',
zip_code => 'A5'
);
my %fips_data;
my $fips_template = join(" ", @field_types{@record_layout});
while(my $fips_line = <>){
@fips_data{@record_layout} = unpack($fips_template, $fips_line);
next if $fips_data{'state_code'} == 52;
print STDOUT join('|', @fips_data{@record_layout});
}
Update: This post and its follow-up keep getting panned.
It would be nice to get some constructive criticism rather than
watching the numbers continue to fall on this, after all I
would like to know what's wrong or could be done better so
I can grow as a Perl programmer.
Thanks,
Mike
"The two most common elements in the universe are hydrogen... and stupidity."
Harlan Ellison