in reply to generate regular expression
Now, much like the other comments in this thread, I'm not really sure what type of order you are looking for in the set. If 2 CAC means 'CACCAC' or 'CAC\w*CAC', etc. Given the fact that I may have missed this, the compilation of the $reg_key can be changed to be something else. Nevertheless, it will still be able to parse the file based of some sort of input, which is what I believe you were generally looking for.#!/usr/bin/perl use strict; use warnings; my $regex_cache = {}; die "Usage $0 [CAC <NUM> TTT <NUM>]\n" if ( @ARGV % 2 ); my %input = @ARGV; # Where the input would be : CAC 2 TTT 2 my $data_set = <DATA>; for my $in ( keys %input ) { my $reg_key = "($in)\{$input{$in}\}"; my $reg = $regex_cache->{$in} ||= qr/($reg_key)/s; print "$1\n" if ( $data_set =~ $reg ); } __DATA__ ATCACCACTTCCTGGACACTACCCTAAACCTTTGAGGA AATAACCGCTTTGTTGTTGCGATCGCCTAATAAATATC AGCGTCTTCGTATGATAAACCAATGCGGAAGTACAAAA
print$_ for(map{chr($_)}split(/\s+/,join(/\B?:\w+[^\s+]/,<DATA>))); __DATA__ 67 111 100 101 32 80 101 114 108
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: generate regular expression
by khoueiry (Initiate) on Apr 01, 2006 at 10:12 UTC |