Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

smarter ?? faster - for that you'll have to benchmark...

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11138432 use warnings; sub randomstring { join '', map +(qw(a b))[rand 2], 1 .. shift } for (1 .. 10) { match( $_, randomstring(4), randomstring(4), 1); } sub match { my ($n, $x, $y, $m) = @_; $x =~ /(.+)$(??{ ($1 ^ substr $y, 0, length $1) =~ tr!\0!!c <= $m ? '' : '(*FAIL)' })/ and print "$n:($-[1],@{[ length $1 ]})($x,$y)\n"; }

Outputs:

1:(1,3)(abba,baaa) 2:(3,1)(bbbb,aaba) 3:(1,3)(abba,abab) 4:(1,3)(abbb,bbaa) 5:(2,2)(baba,bbbb) 6:(1,3)(bbab,aabb) 7:(0,4)(aaaa,aaab) 8:(2,2)(baba,baab) 9:(2,2)(aaba,baaa) 10:(1,3)(bbab,bbba)

I hope I understood your problem correctly...

Update: fixed $_ to $n


In reply to Re: Suffix-prefix matching done right by tybalt89
in thread Suffix-prefix matching done right by baxy77bax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-19 07:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found