Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Pattern Finder

by japhy (Canon)
on Sep 11, 2001 at 05:34 UTC ( #111644=snippet: print w/ replies, xml ) Need Help??

Description: From Pattern Finding. Update: silly me. It works now.
sub find_pat {
  use re 'eval';

  my $n = shift;
  my $re = qq{
(?{ local (@{[ map "\$c$_,", 1 .. $n ]}) = (0) x $n })
^ 
  };
  $re .= qq{
(.+?)
(?:
@{[ join " |\n", map "  \\$_ (?{ local \$c$_ = \$c$_ + 1 })", 1 .. $_ 
+]}
)*
  } for 1 .. $n;
  $re .= qq{
(?(?{ @{[ join ' && ', map "\$c$_", 1 .. $n ]} })|(?!))
\$
};

  return qr/$re/x;
} 
Comment on Pattern Finder
Download Code

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://111644]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (16)
As of 2015-07-01 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (12 votes), past polls