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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |