----- Original Message ----- From: "Kenneth Jideofor [ MTN - Ikoyi ]" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, January 29, 2003 13:50 Subject: File Formatting in Perl
> Hi all, > > I have file whose content is arranged in rows of two lines, each row-pair > separated from the next by a line-space. > I want to rearrange the file in a two-column format such that all the > entries in the first rows in a pair are put in the first column while their > corresponding second rows are put in the second column. > > For instance, > > Given the content of a file as: > > AAAA > BBBB > > CCCC > DDDD > > EEEE > FFFF > > I want it rearranged in the following format using Perl: > > AAAA BBBB > CCCC DDDD > EEEE FFFF > > I look forward to your assistance. my $line = undef; open(FH,"<$ARGV[0]") or die("Cannot open input file"); while(<FH>) { chomp; next unless(length > 0); unless(defined $line){$line = $_} else {print("$line $_\n"); $line = undef} } close(FH) or die 'Close failed for filehandle FH'; *** Untested *** Dirk Bremer - Systems Programmer II - ESS/AMS - NISC St. Peters USA Central Time Zone 636-922-9158 ext. 8652 fax 636-447-4471 [EMAIL PROTECTED] www.nisc.cc _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs