Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Converting fixed record length files to pipe delimited

by unixwzrd (Beadle)
on Feb 20, 2001 at 01:32 UTC ( [id://59565]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Converting fixed record length files to pipe delimited

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

Replies are listed 'Best First'.
Re: Converting fixed record length files to pipe delimited a follow-up
by unixwzrd (Beadle) on Feb 21, 2001 at 19:50 UTC
    Oh, one other thing I forgot to mention, I was only using "A" data types, but this method would work for any type of fixed records with binary or other embedded data types in it, just simply change the field types for the record layout...

    Mike

    "The two most common elements in the universe are hydrogen... and stupidity."
    Harlan Ellison

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://59565]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.