in reply to Arrary issues
One approach is to construct a hash of FILE1 based upon the NAME.
Read FILE2 and see if any records update JOB for a NAME in FILE1.
I am not sure if this is the intent?
Changing all occurrences of MD -> Doctor without reading FILE2 would be easier, but then what is the point of FILE2?.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Data::Dump qw /pp/; $|=1; #turn off buffering to stdout use Inline::Files; use constant {JOB =>0, CITY=>1, STATE=>2}; my %db; <FILE1>; #skip first line of file while (<FILE1>) { next if /^\s*$/; #skip blank lines in file chomp; my ($Name, $Job, $City, $State) = split /\s*,\s*/,$_; $db{$Name}=[$Job, $City, $State]; } <FILE2>; #skip first line of file while (<FILE2>) { next if /^\s*$/; #skip blank lines in file chomp; my ($Name, $Job, $City, $State) = split /\s*,\s*/,$_; if (exists $db{$Name}) { my $current_job = @{$db{$Name}}[JOB]; if ($current_job ne $Job) { print "$Name\'s job changed $current_job->$Job\n"; @{$db{$Name}}[JOB] = $Job; } } } pp \%db; =Prints Jim's job changed MD->Doctor Julie's job changed MD->Doctor George's job changed MD->Doctor Uma's job changed MD->Doctor Pete's job changed MD->Doctor { Bob => ["Nurse", "Pinole", "CA"], George => ["Doctor", "Pinole", "CA"], Jim => ["Doctor", "Pinole", "CA"], Julie => ["Doctor", "San Pablo", "CA"], Kate => ["Nurse", "Oakland", "CA"], Pete => ["Doctor", "San Pablo", "CA"], Sherry => ["Nurse", "Pinole", "CA"], Tara => ["Nurse", "San Pablo", "CA"], Tim => ["Nurse", "Pinole", "CA"], Uma => ["Doctor", "San Pablo", "CA"], } =cut __FILE1__ Name, Job, City, State Jim, MD, Pinole, CA Tara, Nurse, San Pablo, CA Julie, MD, San Pablo, CA Sherry, Nurse, Pinole, CA George, MD, Pinole, CA Tim, Nurse, Pinole, CA Bob, Nurse, Pinole, CA Uma, MD, San Pablo, CA Kate, Nurse, Oakland, CA Pete, MD, San Pablo, CA __FILE2__ Name, Job, City, State Jim, Doctor, Pinole, CA Tara, Nurse, San Pablo, CA Julie, Doctor, San Pablo, CA Sherry, Nurse, Pinole, CA Jan, Doctor, San Pablo, CA George, Doctor, Pinole, CA Tim, Nurse, Richmond, CA Bob, Nurse, Pinole, CA Uma, Doctor, San Pablo, CA Kate, Nurse, Oakland, CA Paul, Doctor, Oakland, CA Ruth, Nurse, Richmond, CA Joe, Nurse, Oakland, CA Nick, Nurse, Pinole, CA Pete, Doctor, San Pablo, CA
|
|---|