Solved

reading/writing to file

Posted on 2003-12-03
2
310 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

733 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