> > > Hi All! > > Is there an easy way (or module) to turn a flat fixed-width > database into > useful data? I would like to dump particular database fields > into a hash. > > > Tom Jones 12345 Something Dr. Atlanta GA 25467 > John Doe 1704 Green Street Boston MA 62481 > Erica Fields 301 w Tree Circle New York NY 91528 > > > Would become... > > > %hash = ( > First_Name => 'Tom', > Last_Name => 'Jones', > City => 'Atlanta', > State => 'GA', > ); > >
unpack() is your friend... use strict; my $t = << "EOT"; Tom Jones 12345 Something Dr. Atlanta GA 25467 John Doe 1704 Green Street Boston MA 62481 Erica Fields 301 w Tree Circle New York NY 91528 EOT # 1234567890123456789012345678901234567890123456789012345678901234567890 # Tom Jones 12345 Something Dr. Atlanta GA 25467 my $template = "a8 a9 a22 a11 a6 a6"; foreach my $line(split(/\n/, $t)) { next unless($t =~ /[a-zA-Z]/); my ($fname, $lname, $street, $city, $state, $zip) = unpack($template, $line); print "Name: $fname $lname\nSTREET: $street\nCITY: $city\nSTATE: $state ZIP $zip\n\n"; } In the absence of evidence of a valiant attempt, I leave you to trim trailing whitespace and populate the hash ;-) -Lynn. _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs