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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:55:56+00:00 2026-06-10T00:55:56+00:00

My input file (~5k lines) format looks something like this foo0: users/user1/temp1 users/user2/temp1 4.0

  • 0

My input file (~5k lines) format looks something like this

foo0: users/user1/temp1 users/user2/temp1 4.0
foo1: users/user2/temp1 users/user4/temp2 users/user4/temp1 1.0
foo2: users/user1/temp3 users/user2/temp3 2.0
foo4: users/user4/temp5 users/user2/temp6 users/user1/temp1 users/user3/temp1 4.0

What my script needs to do is to look at each line, grab each of the paths, open file & check something inside based on it.

For ex: For line 1, the script has to open user1.txt and search for temp1 inside user1.txt and do something. Then go on to user2.txt and look for temp1 inside and do something.

For line 2: Open users2.txt and search for temp1; open users4.txt and search for temp2; open users4.txt and search for temp1.

What’s the quickest way to go about it. I currently open and close one by one, and that seems to take a long time. Any help appreciated, 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-06-10T00:55:57+00:00Added an answer on June 10, 2026 at 12:55 am

    I would do something like this:

    #! /usr/bin/perl
    
    use warnings;
    use strict;
    
    while ( <> ) { 
    
        ## Remove last newline character.
        chomp;
    
        ## Split line with spaces and save paths (all strings but the first and
        ## last one).
        my @paths = split;
        @paths = @paths[ 1 .. $#paths - 1 ];
    
        ## For each path...
        for my $path ( @paths ) { 
    
            ## Split with a slash, get second field and try to open it. 
            my @elements = split m|/|, $path;
            open my $fh, q|<|, $elements[1] or die $!; 
    
            ## Read line by line searching for the third field of the path, do
            ## something if found. You can add a 'last' instruction if you wish.
            while ( my $line = <$fh> ) { 
                chomp;
                if ( $line =~ m/\Q${elements[2]}\E/ ) { 
                    ## Do something;
                }   
            }   
    
            close $fh or warn $!; 
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My task in this lab is to accept multiple input file and the format
I am copying this answer like this for line in fileinput.input(['my_file'], inplace=True): sys.stdout.write('_____ {l}'.format(l=line))
This is one line of the input file: FOO BAR 0.40 0.20 0.40 0.50
I'm trying to open a file for input in Excel with this line :
AIM: I would like to tail the last line of the file.txt and input
If I have an input file like: US, P1, AgriZone, H, 1000, 1200, 1101,
for a programming homework, I'm implementing Prim's algorithm, the format of the input file
I have a file like this: 1234 1234 First Name Last Name And I
I have a log file where some of the entries look like this: YY/MM/DD
I have a text file with several lines in the following format: gatename #outputs

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.