Hello, I am in need of assistance with a small problem I found in my code that has turned into an issue. I am still relatively new to Perl. My data is two text files that look similar to these two examples. My script currently opens the files, puts them into separate comma delimited arrays(@names, @jobs...), and exports certain differences to another text file. What I need is to print out the change of job title from file one to file two, and I also need the name of the persons whose job title changed.

It should look like this: Jim => Prev: MD Now: Doctor for all changed titles. I know my code is stopping at the new name value and I tried different things like another for loop, or adding 1 to $i, and I even looked at changing it to a hash. I can't figure out a way to skip over the new name in the new array and still stay the same in the old one.

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
$file = "1.txt"; (@namesOld = (), @namesNew = (), @jobOld= (), @jobNew= ()); open (FILE, '<', $file) || die; while (<FILE>) { @hospWorkersOld = split(/,/, $_); push (@namesOld, @hospWorkersOld[0]); push (@jobOld, @hospWorkersOld[1]); } close FILE; $file2 = "2.txt"; open (FILE, '<', $file2) || die; while (<FILE>) { @hospWorkersNew = split(/,/, $_); push (@namesNew, @hospWorkersNew[0]); push (@jobNew, @hospWorkersNew[1]); } close FILE; @oldJobs=(); @newJobs=(); @newNames=(); for ($i = 0; $i < scalar(@jobNew); $i++ ) { if ($namesOld[$i] eq $namesNew[$i] && $jobOld[$i] ne $jobNew[$i] +) { #print "$namesNew[$i]--$jobNew[$i]\n"; push (@newJobs, $jobNew[$i]); push (@oldJobs, $jobOld[$i]); push (@newNames, $namesNew[$i]); } }

In reply to 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.