I am a perl beginner and need some help with regex
Input for this code is :
aatgatgataaggtaaggtatgatgatgatgatgatagtagannnnnnnnnatgcatga'/atgca.atgactagca/atgactagcaaggtaaggtaaggtaaggtaaggtatgatgatgannnn./atgatgactagactgacaaggtaaggtaaggtatgatgatgatcgatgacgat... and so on

Here i am trying to assign input file as a scalar variable and trying to find a match of "aaggtaaggt" and then skip some 100 characters whether they are alphabets or symbols or any wildcard characters after skipping exact 100 characters, i am again asking code to start search for match again and every time it finds a match , i am counting and asking to print..

As of my knowledge i have tried using substr of match as pos1 and had set offset for 100 and then assigned that as initial pos for reading second match , but failed to get the correct output, then tried here post match as $' but doubt whether it is correct or not.

#!/usr/bin/perl
$count1 = 0;
open (FILE, "INPUT") || die "cannot open $!\n";
while ($line = <FILE>){

if(($line=~m/(aaggt){2}/ig)&&($'=~m/([atgcn]{100,})/i)) {
$count1 ++ ;
print " " ,$1, "\t";
print "count1 \t " ,$count1 , "\n" ;
}

}

Please, help me figuring out this task. Thanks

Recommended Answers

All 5 Replies

#!/usr/bin/perl -w

use strict;

undef $/;	# Input Record separator

open (FILE, "INPUT") || die "cannot open $!\n"; 
my $var=<FILE>;  # Assign the file handler to scalar variable
close (FILE);

my $match=qq{aaggtaaggt};  # Declare your text
my $count=0;

# ($match)  -> aaggtaaggt
# (.{100})? -> any 100 character match o or 1 times

$count++ while ($var=~ m{($match)(.{100})?}gs);

print "\nAs per rule text '$match' find $count times";
commented: I learned something from his example -- specifically the $count++ while ($var=~ m{($match)(.{100})?}gs); +1

Hi @k_manimuthu Thanks for the reply ur clear way of explaining the code was helpful and i figured it out.

I have a quesion for my problem with using mysql and perl programming.

- data from mysql is logic expression. After query I get it's value on string format:

my $data = "$sex < 1 && $age >= 17 && $age <= 40 && ',1,2,3,' =~m/(,)$optid(,)/";

In this expression $sex,$age,$optid is variables

- How to make Perl understanding this function?
my $sex,$age,$optid;
if ($data) {
........
........
}

as

if ($sex < 1 && $age >= 17 && $age <= 40 && ',1,2,3,' =~m/(,)$optid(,)/) {
........
........
}

Please!!!!

I have a quesion for my problem with using mysql and perl programming.

I think that is a good question but to avoid confusion please start a new thread for it, instead of posting it as a reply to this thread's question.

I think that is a good question but to avoid confusion please start a new thread for it, instead of posting it as a reply to this thread's question.

thank, I've solved my problem. By using eval function

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.