I have 2 tab delimited flattext files. One contains all the major info that I want to search from, the other the info that I want to sort by. They have a common ID column though not identical) so it would seem to be quite straightforward to do this.
In the following code I have put the main db into an array, and the sorting db into a hash. the idea is that on iterating through the array I check to see if the ID exists in the hash and if so put it into the sort field. If it doesn't exist sort field is undefined.
The problem is: it doesn't work!! If anyone could help me achieve this that'd be really great.
Thanks.
my %sort_file;
open (FILE, "$data") or die $!;
@all=<FILE>;
close (FILE);
my $points_total= "/path/points_total.txt";
open FH, "$points_total" or die "Can't open $points_total: $!";
flock (FH, 1) or die "Can't lock $points_total for reading: $!";
my @fh=<FH>;
close FH;
#create hash of sort file
foreach (@fh) {
chomp;
($checkIDNumber, $total_points) = split "\t",$_;
$sort_file{$checkIDNumber} = $total_points;
}
foreach $line (@all){
$line=~s/\n//g;
($undef,$undef,$IDNumber,$Email_address,$Page_Name)=split (/\t/,$line)
+;
if (exists ($sort_file{$IDNumber} )) {
$sortfield = $total_points;
} else {
$sortfield = "";
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.