Functionally
that code would do something similar to this:
open my $fh, '<' , '/tmp/cat-cache' or Carp::croak("Cant open file $@ $! ");
sub lessquote {
my $x = shift;
my $meta = shift; # meta means were repeating thise code for >128
# Special Case for whitespace
if(( not defined $meta ) && ( $x == 9 or $x == 10 ) ){
return chr($x);
}
# Null and M-^@
if( $x == 0 ){
return "^@";
}
# ^A to ^Z as well as M-^A to M-^Z
if( ( 0 <= $x ) && ( $x <= 31 )){
return "^" . chr( $x + ord('A') - 1 );
}
# Also M-^?
if( $x == 127 ){
return "^?";
}
# Does the M- Family
if( $x >= 128 && $x <= 255 ){
return "M-" . lessquote( $x - 128 , 1);
}
return chr( $x );
}
while( my $line = <$fh> ){
$line =~ s{(.)}{ lessquote( ord( $1 ) ) }eg;
}
Not identical, but similar.
NB: lessquote appears to match my 'cat -v' output.
But as you can see, doing the same thing is a bit less than trivial and not directly suited for a regular expression, but still, I don't see why they shelled out to 'cat'.
As far as their style goes
They are shelling out in a bad way, the code style is so 1990's and it should be avoided.
open my $fh , '-|' , 'cat' , '-v' , '/tmp/cat-cache' or Carp::croak("Cant open file $@ $! ");
Syntax:
open my $FILEHANDLE , $OPENMODE, $FILENAME || Carp::croak($ERRORMESSAGE)
open my $FILEHANDLE , $OPENMODE, $SHELLCOMMAND || Carp::croak($ERRORMESSAGE)
open my $FILEHANDLE , $OPENMODE, $SHELLPROGRAM, @ARGS || Carp::croak($ERRORMESSAGE)
Is the "preferred" notation these days for a multitude of reasons.
Of course, you wouldn't ACTUALLY want to use cat, but I've left it in here for a clear example.