osfameron has asked for the wisdom of the Perl Monks concerning the following question:
I've recently got very interested in Ascii art and animation.
I've stumbled across an interesting problem: how to search for one Ascii picture within another. e.g. does the picture:
In pseudocode the best algorithm I've found is:MM oo < -/ contain /^\ ? /^\ C : C : 8===8 |^| ||| -~-~
Data
- Target list
- Match list (the picture to search for)
- Results list
Main sub
- Escape the match list for regex special characters, e.g. .+*?()[]{}
- For each line of target,
- for each match found against first line of match, run submatch specifying the position of the match.
- If submatch returned true, add the line and position to the results list.
- Return all results.
submatch sub
- Taking next lines of target & match, return false if there is no match at specified position.
- Return a true value (like the position of the match) if there are no more lines left of the match.
- Return the value of the *next* submatch (e.g. recurse)
Is there already a module for doing this type of match? Or can anyone suggest a better algorithm? (I think that recursing makes sense for this problem, but I'm open to suggestions!)
Cheerio!
Osfameron
http://osfameron.perlmonk.org/chickenman/
Back to
Seekers of Perl Wisdom