----- Original Message -----
From: "Öznur Taştan" <[EMAIL PROTECTED]>
To: "Randy W. Sims" <[EMAIL PROTECTED]>
Sent: Friday, February 20, 2004 2:03 PM
Subject: Re: all matches of a regex-continued


>
> ----- Original Message -----
> From: "Randy W. Sims" <[EMAIL PROTECTED]>
> To: "Öznur Taştan" <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>; "Perl Lists" <[EMAIL PROTECTED]>
> Sent: Friday, February 20, 2004 1:54 PM
> Subject: Re: all matches of a regex-continued
>
>
> > On 02/20/04 06:06, Öznur Taştan wrote:
> > > You are right but the sets of patterns can include any number of
> patterns
> > > which will mean a variable number of foreach loop and I don't know how
> to
> > > achieve.
> > > thanks
> > > oznur
> > >
> >
> > Ok, welcome to the wonderful world of dynamic code generation. The code
> > below is ugly as sin, but see if it does what you want.
>
> I didn't know something exists like this, thanks that will be very helpful
> but still
> does this solve the problem of regular expression patterns istead of keys
> just as I mentioned in the first mail.
> " I am still dealing with the same problem.
> Rob has suggested me a good solution for macthing consecutive patterns
like
>  H K D  but not more looser ones like for K[ED]{3,5}?  L.{3}A
> andn my poor perl knowledge doesn't help me to generalize it: /"
> thanks a lot
> oznur
>
>
> > #!/usr/bin/perl
> >
> > use strict;
> > use warnings;
> >
> >
> > my $seq = 'xHxxHyyKzDt';
> >
> > my @any = ( '(.+)', '(.+?)' );
> >
> > my @vars = ('a'..'z');
> > my @keys = qw( H K D );
> >
> >
> > my $cmd;
> >
> > my $index = 0;
> > for my $key (@keys) {
> >    $cmd .= "for my \$$vars[$index++] (0..1) {\n";
> > }
> > $cmd .= "for my \$$vars[$index++] (0..1) {\n";
> >
> >
> > $index = 0;
> > $cmd .= "my \$any =  '^' .\n";
> > for my $key (@keys) {
> >    $cmd .= "\$any[\$$vars[$index]] . '$keys[$index++]' .\n";
> > }
> > $cmd .= "\$any[\$$vars[$index]] . '\$';\n";
> >
> > $cmd .= "\$uniq{\"";
> > $index = 0;
> > for my $i ([EMAIL PROTECTED]) {
> >    $cmd .= "\$$i ";
> > }
> > chop $cmd; #remove the last space we added
> > $cmd .= "\"}++ if \$seq =~ /\$any/;\n";
> >
> > $index = 0;
> > for ([EMAIL PROTECTED]) {
> >    $cmd .= "}\n";
> > }
> >
> > #print $cmd;
> > my %uniq;
> > eval $cmd;
> >
> > print join("\n", keys(%uniq)) . "\n";
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > <http://learn.perl.org/> <http://learn.perl.org/first-response>
> >
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to