Hello deadlift

You were on the right road to consider using a hash.

Here is a possible solution using a hash (for the first shorter file).

#!/usr/bin/perl use strict; use warnings; my $File1 = <<EOF; 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 EOF my $File2 = <<EOF; 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 EOF my %occupation; open my $fh1, '<', \$File1 or die $!; <$fh1>; # throw away header line while (<$fh1>) { my ($name, $title) = split /, /; $occupation{$name} = $title; } close $fh1 or die $!; open my $fh2, '<', \$File2 or die $!; <$fh2>; # throw away header line while (<$fh2>) { my ($name, $title) = split /, /; if (exists $occupation{$name} and $occupation{$name} ne $title) { print $name, " => Prev: $occupation{$name}, Now: $title\n"; + } } close $fh2 or die $!;
You can see that I used strict and warnings which you should use (to identify errors or warnings in code).

That requires declaring the variables with my.

Also, it is good practice to check whether a file opening (or closing) occurred without error (the or die $! code on file openings and closings).

Although I didn't use Text::CSV here, it really should be used for more complex csv files.

Output:

C:\Old_Data\perlp>perl test2.pl Jim => Prev.: MD, now: Doctor Julie => Prev.: MD, now: Doctor George => Prev.: MD, now: Doctor Uma => Prev.: MD, now: Doctor Pete => Prev.: MD, now: Doctor

In reply to Re: Arrary issues by Cristoforo
in thread Arrary issues by deadlift

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.