Skip to content

Instantly share code, notes, and snippets.

@rofr
Created August 18, 2015 07:54
Show Gist options
  • Save rofr/f8476e7818c57cdd02c1 to your computer and use it in GitHub Desktop.
Save rofr/f8476e7818c57cdd02c1 to your computer and use it in GitHub Desktop.
I love perl
$ perl text-lint.pl text-input.txt
line 1 violates rule \bhaz\b
my dog haz fleas
line 2 violates rule \bhaz\b
can I haz code, please?
line 3 violates rule \bibm\b
ibm is a big company
#!/usr/bin/perl -w
# Apply a number of regexs to each line of input, print a
# message to STDERR for each match
use strict;
#put your rules here, basically same syntax as NET regex
#\b means word boundary
my @invalid_patterns = (
'\bibm\b', #ibm should be IBM
'\bhaz\b', # bad spelling
);
my $line_no = 0;
while (<>) { #read lines from stdin
my $line = $_;
$line_no++;
for my $regex(@invalid_patterns) {
printf STDERR "line $. violates rule $regex\n$line" if $line =~ $regex;
}
}
my dog haz fleas
can I haz code, please?
ibm is a big company
hazard, avoid false positives
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment