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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:48:33+00:00 2026-05-22T23:48:33+00:00

EDIT: Sorry for the misunderstanding, I have edited a few things, to hopefully actually

  • 0

EDIT: Sorry for the misunderstanding, I have edited a few things, to hopefully actually request what I want.

I was wondering if there was a way to open/join two or more files to run the rest of the program on.

For example, my directory has these files:

taggedchpt1_1.txt, parsedchpt1_1.txt, taggedchpt1_2.txt, parsedchpt1_2.txt etc…

The program must call a tagged and parsed simultaneously. I want to run the program on both of chpt1_1 and chpt1_2, preferably joined together in one .txt file, unless it would be very slow to do so. For instance run what would be accomplished having two files:

taggedchpt1_1_and_chpt1_2 and parsedchpt1_1_and_chpt1_2

Can this be done through Perl? Or should I just combine the text files myself(or automate that process, making chpt1.txt which would include chpt1_1, chpt1_2, chpt1_3 etc…)

#!/usr/bin/perl
use strict;
use warnings FATAL => "all";
print "Please type in the chapter and section NUMBERS in the form chp#_sec#:\n"; ##So the user inputs 31_3, for example
chomp (my $chapter_and_section = "chpt".<>);
print "Please type in the search word:\n";
chomp (my $search_key = <>);

open(my $tag_corpus, '<', "tagged${chapter_and_section}.txt") or die $!;
open(my $parse_corpus, '<', "parsed${chapter_and_section}.txt") or die $!;

For the rest of the program to work, I need to be able to have:

my @sentences = <$tag_corpus>; ##right now this is one file, I want to make it more
my @typeddependencies = <$parse_corpus>; ##same as above

EDIT2: Really sorry about the misunderstanding. In the program, after the steps shown, I do 2 for loops. Reading through the lines of the tagged and parsed.

What I want is to accomplish this with more files from the same directory, without having to re-input the next files. (ie. I can run taggedchpt31_1.txt and parsedchpt31_1.txt…… I want to run taggedchpt31 and parsedchpt31 – which includes ~chpt31_1, ~chpt31_2, etc…)

Ultimately, it would be best if I joined all the tagged files and all the parsed files that have a common chapter (in the end still requiring only two files I want to run) but not have to save the joined file to the directory… Now that I put it into words, I think I should just save files that include all the sections.

Sorry and Thanks for all your time! Look at FMc’s breakdown of my question for more help.

  • 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-22T23:48:34+00:00Added an answer on May 22, 2026 at 11:48 pm

    You could iterate over the file names, opening and reading each one in turn. Or you could produce an iterator that knows how to read lines from sequence of files.

    sub files_reader {
        # Takes a list of file names and returns a closure that
        # will yield lines from those files.
        my @handles = map { open(my $h, '<', $_) or die $!; $h } @_;
        return sub {
            shift @handles while @handles and eof $handles[0];
            return unless @handles;
            return readline $handles[0];
        }
    }
    
    my $reader = files_reader('foo.txt', 'bar.txt', 'quux.txt');
    
    while (my $line = $reader->()) {
        print $line;
    }
    

    Or you could use Perl’s built-in iterator that can do the same thing:

    local @ARGV = ('foo.txt', 'bar.txt', 'quux.txt');
    while (my $line = <>) {
        print $line;
    }
    

    Edit in response to follow-up questions:

    Perhaps it would help to break your problem down into smaller sub-tasks. As I understand it, you have three steps.

    • Step 1 is to get some input from the user — perhaps a directory name, or maybe a couple of file name patterns (taggedchpt and parsedchpt).

    • Step 2 is for the program to find all of the relevant file names. For this task, glob() or readdir()might be useful. There are many questions on StackOverflow related to such issues. You’ll end up with two lists of file names, one for the tagged files and one for the parsed files.

    • Step 3 is to process the lines across all of the files in each of the two sets. Most of the answers you have received, including mine, will help you with this step.

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

Sidebar

Related Questions

EDIT: Sorry about ellipsis that's not what I actually have. For declaring an array
If I have the following code (EDIT: Sorry if I wasn't clear, I want
EDIT Sorry I forgot the most important part here. Each key can have more
Edit: Sorry guys, realised I have no idea when it comes to integrating Webservices
Does anyone have any experience on getting Hibernate working with ZK? Thanks Edit: Sorry
Is there a .net equivalent to the C++ unexpected()/set_unexpected() functionality? Edit: Sorry--I omitted some
Is there a boost equivalent for memcpy? Thanks! EDIT: Sorry, I didn't realize memcpy
EDIT: Sorry, I should have been more clear. My webpage needs to be XHTML
IMPORTANT EDIT: Sorry everyone, i made a big mistake in the structure. char *name;
[edit]: I'm terribly sorry for my timing on asking this question. I've just discovered

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.