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 8800819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:41:24+00:00 2026-06-14T00:41:24+00:00

I have a program expecting input from stdin, OR from a mix of .log

  • 0

I have a program expecting input from stdin, OR from a mix of .log and .log.gz files. Here are the three types of calls I want the program to handle:

cat input.log | prog
prog < input.log
prog input.log input.log.gz

The program considers all input files as one. I was hoping to capitalize on ARGV to process all input uniformly:

while (<>) {
# process input
}

My goal is to process gz files in the same loop. How can this be done? I want to know how messy it is. If it is too bad I will handle gz separately.

I can only use core modules with Perl 5.8.8.

  • 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-06-14T00:41:26+00:00Added an answer on June 14, 2026 at 12:41 am

    You can’t really do that and get the shorthand benefit of the diamond operator.

    • Because you’re going to have to monkey with the input handle, you’re going to need to open the files yourself.
    • You might be able to use @ARGV for this, but you’ll only get the easy handling if you reopen *::STDIN for these files.

      my $file = shift;
      if    ( !$file )           {} # use STDIN as is.
      elsif ( $file =~ /\.gz$/ ) { 
          open( ::STDIN, '-|', "gunzip $file" ) or die "Could not open: $!!";
      }
      else {
          open( ::STDIN, '<', $file ) or die "Could not open $file: $!!";
      }
      
      while ( <> ) { 
          ...
      }
      close STDIN;
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have program that runs fast enough. I want to see the number of
I have a program that gets a JSON from the server using getJSON and
I am trying to execute a program from the Java code. Here is my
I have a bug in a multi-processes program. The program receives input and instantly
I'm trying to read the stdin in my Java program. I'm expecting a series
I wrote a program with java and mysql and now i want to have
Say I have a command line C program which is currently executing, and I
I have program written in C. It takes 2 arguments username/password and try to
I have program that requires Python 3, but I develop Django and it uses
I have program that has a variable that should never change. However, somehow, it

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.