seaver has asked for the wisdom of the Perl Monks concerning the following question:
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>'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Matches but not substituting
by toolic (Bishop) on Jun 03, 2011 at 14:53 UTC | |
by seaver (Pilgrim) on Jun 03, 2011 at 15:14 UTC | |
by GrandFather (Saint) on Jun 04, 2011 at 00:26 UTC | |
by Anonymous Monk on Jun 03, 2011 at 14:55 UTC | |
by toolic (Bishop) on Jun 03, 2011 at 15:10 UTC | |
|
Re: Matches but not substituting
by kennethk (Abbot) on Jun 03, 2011 at 14:55 UTC | |
|
Re: Matches but not substituting
by NetWallah (Canon) on Jun 04, 2011 at 05:07 UTC | |
|
Re: Matches but not substituting
by Anonymous Monk on Jun 03, 2011 at 14:53 UTC | |
by seaver (Pilgrim) on Jun 03, 2011 at 15:02 UTC | |
by Anonymous Monk on Jun 03, 2011 at 15:12 UTC | |
by toolic (Bishop) on Jun 03, 2011 at 15:07 UTC |