First, you need to read up on how to read files. Second, when you want to your code to look something up -- you want to lookup if a name is in the other file -- think of hashes. The following should be useful.
use strict;
use warnings;
my %fileA;
my %fileB;
my %users;
# Read in FileA.
open(A, "FileA") || die "$!\n";
while (<A>) {
my ($name, $machine, $laston) = split(/,/, $_);
$fileA{$name} = [ $machine, $laston ];
}
close(A);
# Read in FileB.
open(B, "FileB") || die "$!\n";
while (<B>) {
my ($name, $password, $location) = split(/,/, $_);
$fileB{$name} = [ $password, $location ];
}
close(B);
# Check for users missing in FileB.
# Merge records found in both FileA and FileB.
foreach my $name (keys(%fileA)) {
if (!exists($fileB{$name})) {
warn("$name was found in file FileA, but not in file FileB.\n");
next;
}
$users{$name} = [ $fileA{$name}, $fileB{$name} ];
#delete($fileA{'name'}); # not needed
delete($fileB{'name'});
}
# Check for users missing in FileA.
foreach my $name (keys(%fileB)) {
if (!exists($fileA{$name})) {
warn("$name was found in file FileB, but not in file FileA.\n");
}
}
# Do something with users.
# Specifically, display matches.
foreach my $name (sort keys(%users)) {
printf("user %s\n".
"machine: %s\n".
"last on: %s\n".
"password: %s\n".
"location: %s\n".
"\n",
@{$users{$name}}
);
}