Perl program to read from multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl program to read from multiple files
# 1  
Old 07-19-2006
Perl program to read from multiple files

Hi,

I need to generate a test data file by reading inputs from multiple files.

A sample pseudo code for this program to read from three files and write to a output file would be like:

open(OUTPUTFILE, "data");
open(INFILE1, "data1");
open(INFILE2, "data2");
open(INFILE3, "data3");

while(<OUTPUTFILE>) {
print OUTPUTFILE "the current line of data1" "the current line of data2" "the current line of data2";
}

Is it possible to do something like this in Perl??

Thanks in Advance..
JYoti
# 2  
Old 07-19-2006
Why not? Just try something like, after open (untested)

while (
$l1 = <INFILE1> ||
$l2 = <INFILE2> ||
$l3 = <INFILE3>
) {
print OUTFILE qq/$l1 $l2 $l3/;
}

But of course, you need to keep track of whether any of the filehandles has reached EOF and intelligently skip them in practice.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

2. Shell Programming and Scripting

Read files in shell script code and run a C program on those files

HI, I am trying to implement a simple shell script program that does not make use of ls or find commands as they are quite expensive on very large sets of files. So, I am trying to generate the file list myself. What I am trying to do is this: 1. Generate a file name using shell script, for... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

3. Shell Programming and Scripting

Retreiving multiple files by changing a parameter with one program

Hi all, I am using following command: perl program.pl input.txt output.txt CUTOFF 3 > groups_3.txt containing program.pl, two files (input.txt, output.txt) and getting output in groups_3.txt: But, I wish to have 30 files corresponding to each CUTOFF ranging from 0 to 30 using the same... (1 Reply)
Discussion started by: bioinfo
1 Replies

4. Programming

C program to read n files and append it to a variable.

I am struck in the code of handling multiple files reading and appending it into a variable. My First file's entire content I have concatenated using strcat(<char pointer>,char array) In the Second file I extract using strtstr() function and below is the code. if( fp2 != NULL){ ... (2 Replies)
Discussion started by: gameboy87
2 Replies

5. Shell Programming and Scripting

Read multiple values from sqlplus in perl

Hello Need your kind support to solve the below issue I am returning oracle column value via sqlplus in the below code my $sqlplus_settings = ''; my $newval = qx { sqlplus -s $connect_string <<EOF set pages 0 feed off $sqlplus_settings select (rcrd_cnt) from... (4 Replies)
Discussion started by: Pratik4891
4 Replies

6. Shell Programming and Scripting

Read from config file and use it in perl program

Hi, I want to configure some values in config file like below work_dir /home/work csv_dir /home/csv sql_dir /home/sqls reportfirst yes and i want to store each value in variable to use it further in my my perl program ?? any thought on this(i am new to perl) ? ... (2 Replies)
Discussion started by: raghavendra.nsn
2 Replies

7. Programming

Control multiple program instances - open multiple files problem

Hello. This shouldn't be an unusual problem, but I cannot find anything about it at google or at other search machine. So, I've made an application using C++ and QtCreator. I 've made a new mime type for application's project files. My system (ubuntu 10.10), when I right click a file and I... (3 Replies)
Discussion started by: hakermania
3 Replies

8. Shell Programming and Scripting

need shell or Perl script to read multiple input

I need shell 0r Perl script to read multiple input and do something and come out example: echo “ enter the host names separated by space “ read servers foreach @servers { do do something done} Here host names like host1 host2 host3 . . . . . . . so on Please help me... (8 Replies)
Discussion started by: sreedhargouda
8 Replies

9. Shell Programming and Scripting

read and match multiple lines in perl

Could any one tell me how to read and match multiple lines in perl? Did this code below still work in this situation? while (<FILE>) { if (/ /) { } } Thanks a lot! (5 Replies)
Discussion started by: zx1106
5 Replies

10. Programming

Splitting my program to multiple source files.

Hi I have a program, say file1.c which included file1.h, the header file which had lots of #define macros and structure definitions used by file1.c I have decided to split the source code into 3 separate files (for logical reasons) file1.c file2.c file3.c Each of these have a... (6 Replies)
Discussion started by: the_learner
6 Replies
Login or Register to Ask a Question