I like the answers I've seen, but I thought you might like to see one that stays very close to the original code, and uses the conditional logic you posted in your Perl comments.
#!/usr/bin/perl -w use strict; my %a = qw( 60622 1 60516 1 60201 1 ); my %b = qw( 90210 1 60622 1 12345 1 ); my %c = qw( 11412 1 32134 1 60201 1 ); open OUTPUT_A, ">a.txt" or die "Can't open OUTPUT_A: $!\n"; open OUTPUT_B, ">b.txt" or die "Can't open OUTPUT_B: $!\n"; open OUTPUT_C, ">c.txt" or die "Can't open OUTPUT_C: $!\n"; while (<DATA>) { chomp; my($fn, $ln, $id) = split(",", $_); if (exists $a{$id}) { print OUTPUT_A $fn, $ln, $id; } elsif (exists $b{$id}) { print OUTPUT_B $fn, $ln, $id; } elsif (exists $c{$id}) { print OUTPUT_C $fn, $ln, $id; } } close OUTPUT_A; close OUTPUT_B; close OUTPUT_C; __END__ Homer,Simpson,60622 Clark,Kent,90210 Fred,Flintstone,00987

This code creates an associative array for each output file, and checks to see if each $id value exists as a key in the table.

As to your other comments... most of us go through such frustrations at times. The other monks have given you great counsel about relaxing.

One recommendation I would add for improving your Perl proficiency: check out the various perlfaq sections in the documentation. Especially perlfaq4 about handling different kinds of data.

You could also browse the Monastery's "Categorized Q&A" and "Tutorials" sections.


In reply to Re: A Love/Hate Relationship - A Long Time Newbie's Current Block by ChrisS
in thread A Love/Hate Relationship - A Long Time Newbie's Current Block by bivouac

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.