943,945 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 1450
  • Perl RSS
Oct 28th, 2009
0

Perl regex

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
riya0707 is offline Offline
2 posts
since Oct 2009
Oct 28th, 2009
1
Re: Perl regex
Perl Syntax (Toggle Plain Text)
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4.  
  5. undef $/; # Input Record separator
  6.  
  7. open (FILE, "INPUT") || die "cannot open $!\n";
  8. my $var=<FILE>; # Assign the file handler to scalar variable
  9. close (FILE);
  10.  
  11. my $match=qq{aaggtaaggt}; # Declare your text
  12. my $count=0;
  13.  
  14. # ($match) -> aaggtaaggt
  15. # (.{100})? -> any 100 character match o or 1 times
  16.  
  17. $count++ while ($var=~ m{($match)(.{100})?}gs);
  18.  
  19. print "\nAs per rule text '$match' find $count times";
Reputation Points: 55
Solved Threads: 24
Junior Poster in Training
k_manimuthu is offline Offline
93 posts
since Jun 2009
Oct 29th, 2009
0
Re: Perl regex
Hi @k_manimuthu Thanks for the reply ur clear way of explaining the code was helpful and i figured it out.
Last edited by riya0707; Oct 29th, 2009 at 9:08 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
riya0707 is offline Offline
2 posts
since Oct 2009
Oct 31st, 2009
0

How to convert string to an expression in PERL

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!!!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
thangdd is offline Offline
2 posts
since Oct 2009
Oct 31st, 2009
0
Re: Perl regex
Quote ...
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.
Reputation Points: 153
Solved Threads: 142
Master Poster
d5e5 is offline Offline
740 posts
since Sep 2009
Nov 3rd, 2009
0

How to convert string to an expression in PERL

Click to Expand / Collapse  Quote originally posted by d5e5 ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
thangdd is offline Offline
2 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: Issue with Cron and Perl Script Variables
Next Thread in Perl Forum Timeline: [PROBLEM] inverting a list





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC