?
Solved

reading/writing to file

Posted on 2003-12-03
2
Medium Priority
?
320 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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 …
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

743 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