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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:38:41+00:00 2026-06-06T14:38:41+00:00

Perl offers this very nice feature: while ( <> ) { # do something

  • 0

Perl offers this very nice feature:

while ( <> )
{
    # do something
}

…which allows the script to be used as script.pl <filename> as well as cat <filename> | script.pl.

Now, is there a way to determine if the script has been called in the former way, and if yes, what the filename was?

I know I knew this once, and I know I even used the construct, but I cannot remember where / how. And it proved very hard to search the ‘net for this (“perl stdin filename”? No…).

Help, please?

  • 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-06T14:38:42+00:00Added an answer on June 6, 2026 at 2:38 pm

    The variable $ARGV holds the current file being processed.

    $ echo hello1 > file1
    $ echo hello2 > file2
    $ echo hello3 > file3
    $ perl -e 'while(<>){s/^/$ARGV:/; print;}' file*
    file1:hello1
    file2:hello2
    file3:hello3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Perl 5.14 gives us the extended each function which operates on arrays as well
Perl allows ... $a = fee; $result = 1 + f($a) ; # invokes
Perl script needs to receive ajax request, send a success message back to browser,
My Perl script needs to run multiple threads simultaneously... use threads ('yield', 'exit' =>
My Perl script is generating an excel sheet. Output P MON #N/A XML xx
Perl noob here - i have the following script if(substr($pc, 3,1)!= ){ $newpc =
Perl code fragment: my $export = $doc; $export =~ s:\.odt:\.pdf:; How would this be
In a Perl script, I want to prompt the user for input and offer
Perl: $string =~ s/[áàâã]/a/gi; #This line always prepends an a $string =~ s/[éèêë]/e/gi; $string
Perl allows you to use the '..' operator to return a slice from an

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.