Solved

reading/writing to file

Posted on 2003-12-03
2
280 Views
Last Modified: 2010-03-04
i have 12 files (one for each month) with data in them.

i want to read each file (files are named filea, fileb, filec etc...) in order from file a to filel and store the contents in a new file (called newfile).

each file contains 3 lines of data

0
Comment
Question by:plennon
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
mrh30 earned 50 total points
Comment Utility
#!/usr/bin/perl -w

use strict;

my @files = qw/filea fileb filec filed filee filef fileg fileh filei filej filek filel/;

open OUTPUT ">newfile";
foreach my $file (@files) {
    open INPUT, "<$file";
    while (<INPUT>) {
        print OUTPUT $_;
    }
    close INPUT;
}
close OUTPUT;
0
 
LVL 3

Expert Comment

by:mrh30
Comment Utility
Ooops, forgot a couple of spaces - "> newfile" and "< $file"
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now