my @fields = qw( num address image neighborhood modelname modelelevation bedrooms bathrooms typeoffoundation schooldistrict price paymentsfrom readydate phonenumber email ); my %m; # key: neighborhood name. value: array of records. { open FILE, "< $datafile" or &fatal_error("Unable to open $datafile"); &lock(FILE); while ( ) { chomp; my %rec; @rec{@fields} = split /``/; # put each record into the list for that neighborhood: push @{ $m{ $rec{'neighborhood'} } }, \%rec; } &unlock(FILE); close FILE; } open FILE, "< $template" or &fatal_error("Unable to open $template"); &lock(FILE); while () { open FILE, "< $template" or &fatal_error("Unable to open $template"); &lock(FILE); while () { if (//) { print < Address Model Name Price Availability EOF foreach $neighborhood ( sort keys %m ) { print < $neighborhood EOF for my $rec ( @{ $m{ $neighborhood } } ) { print < $r->{'address'} "The $r->{'modelname'}" $r->{'price'} $r->{'readydate'} EOF } } print "\n"; } } &unlock(FILE); close FILE;