Update: Typo found by toolic and subsequently Anon. Thanks!
Dear allThis seems like it should be pretty obvious, and it works for everything else, so I'm convinced I'm missing something. I do a match on a string, and then change that string into a URL.
Sample string: LOC100282561 [Source:RefSeq peptide;Acc:NP_001148941]
Desired match: LOC100282561
Desired substitution: <a href="http://www.ncbi.nlm.nih.gov/sites/entrez?db=gene&term=LOC100282561" target="_blank">LOC100282561</a>
use strict; use warnings; my $Text="LOC100282561 [Source:RefSeq peptide;Acc:NP_001148941]"; my %VisitedLinks=(); #Searching for NCBI Entrez Gene IDs + + $_ = $Text; my @OriginalArray = /(LOC\d{9})/g; for (my $i=0; $i < @OriginalArray; $i++) { if (!defined($VisitedLinks{$OriginalArray[$i]})) { $VisitedLinks{$OriginalArray[$i]} = 1; my $Link = EntrezGeneLinks($OriginalArray[$i]); my $Find = $OriginalArray[$i]; $Text =~ s/$Find$/$Link/g; } } print $Text,"\n"; sub EntrezGeneLinks { my ($ID) = @_; return '<a href="http://www.ncbi.nlm.nih.gov/sites/entrez?db=gene& +term='.$ID.'" target="_blank">'.$ID.'</a>'; }
In reply to Matches but not substituting by seaver
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |