First off, this iteration is significantly improved over the last version. This is a very good thing!

Secondly, I'm glad you found my response useful. That you choose not to use hashes is your own business. I just call'em as I see'em.

A few thoughts on your current solution:

  1. Good usage of my. I commend you.
  2. While chomp does work over a list, I had to look that up just now. I suspect that most Perl'ers wouldn't know that, either. I'd recommend commenting that. (Or, I'm just stupid, which is a distinct possibility!)
  3. chomp the line, then split it. It's more intuitive. Or, just do the chomp over @matched. Plus, you chomp @record when it's already been chomped above. That's redundant.
  4. You can find a better variable name than $lic. Don't shorten a variable name. You'll spend more time trying to figure out what that variable was than typing a longer name. Or, since you only use it once, why even create it?
  5. You do a grep twice through @phoneBook. It's better to get the matches, then check to see if you have any. Only one grep, which can be an expensive action.
  6. If you only want to work with the first match, why loop through all the matches? If you only want the first, use $lines[0] or, even better, discard all the matches but the first.
  7. If you're doing something across 5 records, use an arrayslice or a for-loop. It's harder to read if it's all written out. I know that if I see five explicit accesses to an array, I'm looking for a reason. Hopefully, the reason isn't that the writer doesn't know about slicing or for-loops. :)
chomp @matched; foreach my $match (@matched) { my @record = split(/,/, $match); my ($lname, $fname) = split(/\s+/, uc($record[5])); my $name = "$lname " . substr($fname, 0, 2); if (my ($first_matched) = grep /$name/, @phoneBook) { my @line = split /,/, $first_matched; print RESULTS "$record[0],UNKNOWN,$record[$#record],SLC,"; print RESULTS "$line[$_]," for (0 .. 4); print RESULTS "$name\n"; } else { print UNMATCHED "$record[$_]," for (0,5,7,2,3,4); print UNMATCHED "UNKNOWN,\\N,\\N\n"; } }

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.


In reply to Re(5): Comparing two files by dragonchild
in thread Comparing two files by bman

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.