#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my @files = @ARGV; my %people; for my $file (@files) { open my $fh, '<', $file or die $!; <$fh>; # Skip the header line. while (<$fh>) { chomp; my ($name, $job, $city, $state) = split /,\s*/; @{ $people{$name}{$file} }{qw{ job city state }} = ($job, $city, $state); } } for my $person (keys %people) { my $facts = $people{$person}; my @changes; for my $fact (qw( job city state )) { push @changes, $fact if ($facts->{ $files[0] }{$fact} // "") ne ($facts->{ $files[1] }{$fact} // ""); } say "$person =>", map {; " $_ Prev: ", $facts->{ $files[0] }{$_} // '-', ' Now: ', $facts->{ $files[1] }{$_} // '-' } @changes if @changes; }
It's a bit tricky as it's possible to have people in one file that don't exist in the other.
Loading the input could be done via Text::CSV_XS if it's a real CSV, i.e. if the fields can get quoted or contain quoted or escaped commas etc.
In reply to Re: Arrary issues
by choroba
in thread Arrary issues
by deadlift
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |