The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read list of filenames from text file and remove these files in multiple directories fxvisions Shell Programming and Scripting 5 08-07-2008 03:59 PM
read and match multiple lines in perl zx1106 Shell Programming and Scripting 5 03-14-2008 10:21 PM
Multiple Files deletion in perl pulkit Shell Programming and Scripting 1 02-12-2008 05:55 AM
How to read from multiple files cedrichiu Shell Programming and Scripting 5 07-10-2007 11:49 AM
Splitting my program to multiple source files. the_learner High Level Programming 6 06-04-2007 10:53 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-19-2006
jyotipg jyotipg is offline
Registered User
  
 

Join Date: Oct 2001
Location: Bangalore
Posts: 95
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 (permalink)  
Old 07-19-2006
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0