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


In reply to Re: Converting fixed record length files to pipe delimited by unixwzrd
in thread Converting fixed record length files to pipe delimited by akm2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.