Skip to content

Instantly share code, notes, and snippets.

@rjbs
Created March 25, 2011 03:22
Show Gist options
  • Save rjbs/886314 to your computer and use it in GitHub Desktop.
Save rjbs/886314 to your computer and use it in GitHub Desktop.
make it easy to see CRLF anomalies
use strict;
use Term::ANSIColor;
my $CR = "\x0d";
my $LF = "\x0a";
my %rep = (
$CR => color('bold magenta') . "␍",
$LF => color('bold yellow') . "␤",
'' => color('bold black'), # If you can't read bright black on your terminal,
# replace "bold black" with "reset"
);
sub clarified {
my ($str) = @_;
my @lines = split /($CR$LF|$CR|$LF)/, $str;
my $return;
for my $line (@lines) {
unless ($line =~ /$CR|$LF/) {
$return .= $line;
next;
}
$return .= $rep{$_} for split //, $line;
$return .= $rep{''} . "\n";
}
return $return;
}
print clarified($_) for <>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment