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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:43:53+00:00 2026-05-25T11:43:53+00:00

I am reading file contents in perl by following code my @files = glob($PATH/*);

  • 0

I am reading file contents in perl by following code

my @files = glob("$PATH/*");
foreach my $file (@files){
    open(MYFILE,"<$file");
    my @fileContent = <MYFILE>;
    close(MYFILE);
}

Now, I want to prepend auto-incrementing number to each line. Something like —

fileContent[0] = 1: This
fileContent[1] = 2: is
fileContent[2] = 3: a
fileContent[3] = 4: text
fileContent[4] = 5: file.

Does someone know an efficient way to do it?

Thanks!

  • 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-25T11:43:54+00:00Added an answer on May 25, 2026 at 11:43 am

    How about a one-liner?

    perl -wne 'print "$.: $_"; close ARGV if eof;' path/*
    

    Or inside a script, with an array:

    use strict;
    use warnings;
    use autodie;
    
    while (<tmp/data*>) {
        open my $fh, '<', $_;
        my @fileContent;
        push @fileContent, "$.: $_" while <$fh>;
    }
    

    Documentation on $. here.

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

Sidebar

Related Questions

With the following file reading code: using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read,
I am reading the contents of the file using fread into an char array.
I am using the following method for reading Csv file content: /// <summary> ///
So I have the following code where I should read a Text File (This
#!/usr/bin/perl while (true) { #Obj: open dir, get flat-file which was exported from bteq
I want to read the contents of following file types using C#: RTF PDF
I am reading in a text file using FileInputStream that puts the file contents
I have a TextView whose contents are copied from a text file. Now each
i just create reading file feature. In general, what kind PHP class that usually
I am Reading Excel File in .Net Framework 1.1 , using C# . I

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.