This was the first part of the problem that I would like to store the hash line by line possibly in a database. Since, I'm not familiar with databases, you sample code would really help me.sub read_dict{ my $file=$_[0]; my $p=$_[1]; my $direction=$_[2]; my %dict1; open( FILE, "gunzip -c $file |") or die $!; # for each line of input file while (<FILE>) { chomp; local ($l1, $l2, $pr) = split /\|\|\|/; chomp ($l1, $l2,$pr); my @pr = split (/\s/,$pr); chomp $pr[1]; if ($direction) { if ($pr[3]>=$p) { $l1 =~ s/[[:punct:]]//g; $l1 =~ s/\s+/ /g; $l2 =~ s/[[:punct:]]//g; $l2 =~ s/\s+/ /g; $l2 =~ s/^\s+//; $l2 =~ s/\s+$//; $l1 =~ s/^\s+//; $l1 =~ s/\s+$//; chomp ($l1, $l2); if ($l2 && $l1) { push( @{$dict1{lc($l1)}}, lc($l2) );} }} else { if ($pr[1]>=$p) { $l1 =~ s/[[:punct:]]//g; $l1 =~ s/\s+/ /g; $l2 =~ s/[[:punct:]]//g; $l2 =~ s/\s+/ /g; $l2 =~ s/^\s+//; $l2 =~ s/\s+$//; $l1 =~ s/^\s+//; $l1 =~ s/\s+$//; chomp ($l1, $l2); if ($l2 && $l1) { push( @{$dict1{lc($l2)}}, lc($l1) );} }} } # return the hash of arrays!!! return \%dict1; }
Si I want to convert the dict search from hash to SQL format since it is the way to access database. I'd appreciate your helps.if (grep {$_ eq $string} @uniq_strings) { $match++ ; } #using hash elsif (exists $dict{$string}) { # loop over all elements in array of hash LOOP: foreach $element (@{$dict{$string}}) { if (grep {$_ eq $element} @uniq_strings) { $match++ ; last LOOP; } } }
In reply to storing a large hash in a database by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |