in reply to Re^2: Comparing a list to a tab delimited text file
in thread Comparing a list to a tab delimited text file
After having done that, you read your XML file and, for each node of interest, you look up the hash to see if the word exists. If it does, you retrieve the information from the corresponding value and update your XML content.
Pseudo-code for building the hash:
Then, when reading the XML file, you lookup the word of interest in the hash:my %hash; open my $TAB, "<", $tab_file or die "Cannot open $tabfile $!"; while (my $line = <$TAB>) { my $key = (split /\t/, $line)[0]; $hash[$key] = $line; } close $TAB;
You could also preprocess the $line when reading the tab separated file and store in the hash not the full line, but only the part of the data that you need, in a format that makes it easier to use (perhaps as an array ref, for example). Whether this is a good idea depends on your data (are you likely to user almost all entries of the TSV file, or only a few of them? Are you likely to use the TSV entries several times? and so on).if (exists $hash{$xml_word}) { my $line = $hash{$xml_word}; # now do what you want with $line }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Comparing a list to a tab delimited text file
by Azaghal (Novice) on Mar 19, 2018 at 10:22 UTC |