<?xml version="1.0" encoding="windows-1252"?>
<node id="1021773" title="Re: Writing Program With Hashes and Loops For Files With Data in Columns" created="2013-03-05 03:55:41" updated="2013-03-05 03:55:41">
<type id="11">
note</type>
<author id="1007649">
arnaud99</author>
<data>
<field name="doctext">
&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;
I have looked at the code and I have written a program that could be used as a starting point for what you are trying to achieve.&lt;/p&gt;
&lt;p&gt;
This program does not cover all of what you are trying to do, it simply goes up to splitting the milcar file and loading a hash. I hope this gives you an idea of some perl's best practises (or what I would consider best practises), and help you complete your task.
&lt;/p&gt;
&lt;p&gt;
Kind regards.
&lt;/p&gt;
Arnaud
&lt;code&gt;
use strict; # Please use these 2 pragmas
use warnings;

use autodie; #this one comes handy as well

if (@ARGV !=4 ) {
	die "Ooops etc..";
}

	# a more descriptive name for your vars, otherwise you may as well
	# use $ARV[0], $ARGV[1] etc...
my ($milcar_filename, $check_file, $matches_file, $three_column_file) = @ARGV;

#use the 3 args version of open;
open my $fh, '&lt;', $milcar_filename; 
				#prg will 'die' if file error due to the autodie pragma
	
	#store some values into a hash	
my %hash;		
while my $line(&lt;$fh&gt;) {
	chomp $line;

		# I assume here that the milcar file is pipe separated
		# but replace the separator with the separaor of your choice
	my ($last_name, $first_name, $integer1, $word1,
			$integer2, $word2, $real_number) = split /\|/, $line;

		#build a key, see if the key already exists, and
		# update with the latest int2 value, if larger.
	my $key = $last_name . '_' . $first_name;
	if (exists $hash{$key} ) {

	   	if ($integer2 &gt; $hash{key} ) {
			$hash{$key} = $integer2;
		}
	}
	else {
		$hash{$key} = $integer2;
	}
}

&lt;/code&gt;</field>
<field name="root_node">
1021758</field>
<field name="parent_node">
1021758</field>
</data>
</node>
