Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Regexp string concat

by CombatSquirrel (Hermit)
on Jun 14, 2004 at 17:37 UTC ( [id://366634]=note: print w/replies, xml ) Need Help??


in reply to Regexp string concat

I hacked this piece of code together. It may work for you or it may not. I think it is pretty straightforward, except for the two-level Schwartzian transform-like anonymous array nesting (Data::Dumper should help, though)...
#!perl use strict; use warnings; my $string = "EICHENBAUMSCHULE"; my @query = qw/EIC BAUM UMS CHU LE/; @query = sort { $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] } grep { $_->[1] > -1 } map { [$_, index($string, $_), index($string, $_) + length($ +_) - 1] } @query; my @matches; @query or die "No matches"; my $i = -1; my $p = -2; for (@query) { if ($p + 1 < $_->[1]) { ++$i; } push @{$matches[$i]}, $_; $p = $_->[2]; } @matches = sort { $b->[0] <=> $a->[0] } map { [$_->[-1]->[2] - $_->[0]->[1] + 1, $_] } @matches; print "Longest continuous match has length $matches[0]->[0]\n\n"; print "$string\n"; for (@{$matches[0]->[1]}) { print ' ' x $_->[1] . $_->[0] . "\n"; }
Hope this helped.
CombatSquirrel.
Entropy is the tendency of everything going to hell.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-29 11:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found