Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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 = ""; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sorting an array from two sources
by pzbagel (Chaplain) on Oct 21, 2003 at 22:18 UTC | |
by Anonymous Monk on Oct 21, 2003 at 22:56 UTC | |
|
Re: sorting an array from two sources
by Roger (Parson) on Oct 21, 2003 at 23:57 UTC | |
by Anonymous Monk on Oct 22, 2003 at 07:04 UTC | |
by Roger (Parson) on Oct 22, 2003 at 21:56 UTC |