Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 215943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:31:05+00:00 2026-05-11T18:31:05+00:00

I ran across a very strange line of code in a legacy Perl application.

  • 0

I ran across a very strange line of code in a legacy Perl application. The code here is part of a homegrown RSS reader that does some caching to prevent being blacklisted.

open(CAT, "/usr/bin/cat -v /tmp/cat-cache 2>&1|");

Does it seem likely that the original author ran the results through cat -v to strip out non-printing characters to deal with any number of character sets? Wouldn’t this make more sense using a regular expression in Perl itself? Also, I am most perplexed by the pipe on the end.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:31:05+00:00Added an answer on May 11, 2026 at 6:31 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran across some very interesting code that makes me wonder about what bool
I am reviewing some perl code and ran across this line $> = $<;
I ran across an oddity here: https://stackoverflow.com/a/11084038/636656 It appears that assigning to a name
I ran across an interesting issue today. We have an application that utilizes Zend
I have this code below. I randomly ran across that it will work if
I ran across some code like this today; having a flow control flag that
I ran across this code recently which is part of a template class: operator
I ran across some C++ code recently that typedef ed a struct in a
Ran across this line of code: FormsAuth = formsAuth ?? new FormsAuthenticationWrapper(); What do
I ran across some code recently at work (recreated to be similar to what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.