Solved

reading/writing to file

Posted on 2003-12-03
2
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
mrh30 earned 50 total points
ID: 9865526
#!/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
ID: 9865532
Ooops, forgot a couple of spaces - "> newfile" and "< $file"
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Six Sigma Control Plans

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