It's a public holiday in Queensland, so nothing better to do than smash out this week's The Weekly Challenge early.
There probably is some CPAN module that does this, but I avoid using CPAN modules for TWC, except List::Util (which is in Perl core).
For this task, I went through a loop one letter at a time. That string can be considered a base string of both strings if the base string is repeated one or more times to match the entire string.
» ./ch-1.pl abcdabcd abcdabcdabcdabcd abcd abcdabcd » ./ch-1.pl aaa aa a
This task was more straight forward, and can be broken into the following steps:
- Check the input is a file and readable.
- Read the file, and slurp it into a string.
- Remove characters to exclude.
- Put the words (separated by white-spaces
\s+) into a frequency hash.
- Sort the frequencies numerical.
- Display the strings that match the frequency in order.
» ./ch-2.pl input.txt 1 But City It Jet Juliet Latino New Romeo Side Story Their Then West York adaptation any anything at award-winning away become before begin best classic climactic coexist control dance do doesn't end ending escalates families feuding form former friend gains gangs goes happened hatred heartbreaking highway hoping in know love lovers meet meeting neither no one plan planning point romantic rumble run secret sends sister streets strikes terribly their two under understanding until violence warring what when where white whoever wins with wrong younger 2 Bernardo Jets Riff Sharks The by it led tragedy 3 Maria Tony a can of stop 4 to 9 and the