Created
August 18, 2015 07:54
-
-
Save rofr/f8476e7818c57cdd02c1 to your computer and use it in GitHub Desktop.
I love perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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