I repeat the file and in every line I am looking for a regular expression. If a regular expression is found, I just want to print “he found” and then the location of the index where it was found on this line.
Example:
looking for: 'HDWFLSFKD' need index between two Ds line: MLTSHQKKF*HDWFLSFKD*SNNYNSKQNHSIKDIFNRFNHYIYNDLGIRTIA output: 'its found' index location: 10-17
The above “search” is pretty simple, but I plan on having complex regex expressions. So basically just want to know if a regular expression is found in a string, how can we get its location by index?
Here is the code that I still have:
foreach my $line (@file_data) { if ($line=~ /HDWFLSFKD/){ print "it found\n"; print "but at what index are the two Ds"; } else { $sequence.=$line; print "came in else\n"; } }
scott
source share