Among the other obvious defects, you have four sets of capturing parens and purport to print a fifth match. Not today. Moreover the ">" just after the caret (anchor) means the regex can't match the data you supplied. Please, be careful to post code that does what you say, to avoid wasting the Monks time and -- all too often -- sending folks off on a wild goose ^H^H^H^H^H camel chase.
Did you perhaps mean this?
#!/usr/bin/perl use strict; use warnings; # 829503 # info to be extracted: chr1:67208779-67210057:+ my %loc; =head original with captures highlighted while(<LOC>){ chomp; if(/^>(\w+)\s\w+\=(chr\w+)\:(\d+)\-(\d+)/) -------------$1------------$2------$3-----$4- $loc{$1} = "$2:$3:$4:$5"; print $loc{$1}."\n"; } } =cut while(<DATA>) { chomp; if(/^(.+)\s.+=(chr\d):(\d+)\-(\d+).+(?:=\+\s)(.*)/) { print "\t$1 | $2 | $3 | $4 | $5 |\n\n"; $loc{$1} = "$1:$2:$3:$4:$5"; print $loc{$1}."\n"; } else { print "No matches\n"; } } __DATA__ hg19_ensGene_ENST00000237247 range=chr1:67208779-67210057 5'pad=0 3'pa +d=0 strand=+ repeatMasking=none
The above produces the following:
ww@GIG:~/pl_test$ perl 829503.pl hg19_ensGene_ENST00000237247 | chr1 | 67208779 | 67210057 | repeat +Masking=none | hg19_ensGene_ENST00000237247:chr1:67208779:67210057:repeatMasking=none ww@GIG:~/pl_test$
Update: s/ahchor/anchor/
In reply to Re: Using regular expression to extract info from input line
by ww
in thread Using regular expression to extract info from input line
by biobee07
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |