Dear Monks,

There are times when I love Perl, but there are times when I hate it. I love the easy questions but once things get a little complex, I get completely lost.

I think most of my hate stems from the fact that I'm not a programmer by trade and approach things incorrectly in the Perl and programming worlds - I've tried everything it seems (psuedocode, Llama, Camel, Cookbook, Perldocs, Perl Monks) and I still get stuck @ the stupidest places. Case in point this problem I'm currently having.

I have three sets of data that are comprised of IDs that overlap. I have another set of data that contains a bunch of fields including the ID from the original sets of data. How can I sort the data using IF/ELSIF statements into different OUTPUT files? Should I be using hashes and not arrays for the original data sets? Why do I suck so bad? Any other tips for someone still struggling with Perl after years of tinkering?

#!/usr/bin/perl -w use strict; my @a = qw( 60622 60516 60201 ); my @b = qw( 90210 60622 12345 ); my @c = qw( 11412 32134 60201 ); 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(",", $_); # print $fn, $ln and $id to OUTPUT_A if $id = @a[0,1,2...n] # elsif print $fn, $ln and $id to OUTPUT_B if $id = @b[0,1,2...n] # elsif print $fn, $ln and $id to OUTPUT_C if $id = @c[0,1,2...n] + } close OUTPUT_A; close OUTPUT_B; close OUTPUT_C; __END__ Homer,Simpson,60622 Clark,Kent,90210 Fred,Flintstone,00987
you can't be what you were...so you better start being just what you are....

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