Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Converting fixed record length files to pipe delimited

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


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 22, 2001 at 00: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
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-06-15 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.