Here is another script that will search for a given sequence at a given spacing. It can be applied to any text, without requiring it to be stripped first. The assumption here is that spacing and punctuation will be ignored.
#!/usr/bin/perl
use strict;
use warnings;
my ($message, $spacing);
if ($#ARGV >= 1) {
$message = shift;
$spacing = shift;
} else {
die "Usage: els_find.pl message spacing files\n";
}
$spacing > 0 or die "Spacing must be greater than zero\n";
# Build a pattern that will recognize the message in regular
# text, ignoring punctuation and spacing.
my @letters = split //,$message;
my $pattern = join("(?:[^a-z]*[a-z]){$spacing}",@letters);
my $re = qr/($pattern)/i;
# Allow minimal wrapping across lines without having to slurp
# the whole file.
$/ = ''; # paragraph mode
while (<>) {
chomp;
if ($_ =~ $re) {
print "Matched: *$1* at paragraph $. of file $ARGV\n";
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.