?
Solved

reading/writing to file

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
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…
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
Suggested Courses

864 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