By the words 'that will detect', do you actually need to know which combination of CR/LF you have been passed in some input? Because if all you really need to do is delete these characters from a string of text, then you can simply use one of the following lines:
$text =~ tr/\r\n//d; # using tr///
$text =~ s/[\r\n]+//g; # using s///
I'm not sure if the following could actually be useful or not, but who knows? I'll post it and you can do whatever you please with it. I only included the data you presented, so it's not setup for things like mac detection.
# Contains a linefeed
if ($text =~ /\n/) {
# Also contains a carriage return
if ($text =~ /\r/) {
print "Seems like DOS text.\n";
} else {
print "Seems like unix text.\n";
}
} else {
print "No linefeeds detected in the text.\n";
}
|