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";
}
}
-
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.
|