Well, I'm still not sure that I really grasp what it is you're trying to do, but maybe this will be of some help. Changes the lines in the second file if the first field in the line is contained as the first field in a line in the first file (combining data from the two files), or does nothing if not:

#!/usr/bin/perl use strict; use warnings; use feature 'say'; use Data::Dumper; my @data1 = ( ['Aspergillus_clavatus_1', 'XP_001276684.1', 'pectate lyase, puta +tive [Aspergillus clavatus NRRL 1]'], ['Aspergillus_fumigatus_2', 'XP_001276694.1', 'conserved hypotheti +cal protein [Aspergillus fumigatus NRRL 1]'], ['Aspergillus_flavus_3', 'XP_001276726.1', 'tyrosinase central +domain protein [Aspergillus flavus NRRL 1]'], ['Aspergillus_terreus_4', 'XP_001276738.1', 'endoglucanase, puta +tive [Aspergillus terreus NRRL 1]'] ); my %data1; for my $record ( @data1 ) { my ( $old, $new, $text ) = @{ $record }; $data1{ $old } = { new => $new, text => $text }; } my @data2 = ( ['Aspergillus_clavatus_1', 'Aspergillus_flavus_198', 'Aspergillus_ +terreus_166', 'Aspergillus_fumigatus_2'], ['Aspergillus_clavatus_1', 'Aspergillus_flavus_3', 'Aspergillus_ +terreus_4', 'Aspergillus_fumigatus_2'], ['Aspergillus_clavatus_3', 'Aspergillus_flavus_198', 'Aspergillus_ +terreu_166', 'Aspergillus_fumigatus_16'] ); my @results; for my $row ( @data2 ) { my $lookup = shift @{ $row }; push @results, exists $data1{ $lookup } ? join "\t", $data1{ $lookup }->{'new'}, $data1{ $lookup }->{'te +xt'}, join "\t", @{ $row } : join "\t", $lookup, join "\t", @{ $row }; } say Dumper \@results; __END__
Output:
$VAR1 = [ 'XP_001276684.1 pectate lyase, putative [Aspergillus clav +atus NRRL 1] Aspergillus_flavus_198 Aspergillus_terreus_166 +Aspergillus_fumigatus_2', 'XP_001276684.1 pectate lyase, putative [Aspergillus clav +atus NRRL 1] Aspergillus_flavus_3 Aspergillus_terreus_4 Aspe +rgillus_fumigatus_2', 'Aspergillus_clavatus_3 Aspergillus_flavus_198 Aspergi +llus_terreu_166 Aspergillus_fumigatus_16' ];

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re^5: Replace table values from text database by 1nickt
in thread Replace table values from text database by Alfumao

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.