[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Parsing Script Revisited



I feel I'm really close on this one. I've got a hacked bopy of File::Sort
which sorts my file (in the form "userID\tDate\tetc.\n") by date, and a
regular one which will search by ID. Strangely enough, the normal one is
File::Sort2, and the hacked one is File::Sort. =)

Anyway, the idea is to take one file, sort it by date, then look at the
date of the first line. That becomes a tag to check the rest of the lines
against, and when it comes to a line with a different date, it sets that to
the next tag, and prints out all the data it has stored so far. It sorts
that data by ID (it's already sorted by date) and reads it back in,
printing it out to a master output file, and continuing the cycle for the
next date.

I'm sure I've done something relatively stupid- it's not even outputting to
my temp2 file yet. So you needn't worry about the hacked File::Sort-
although if anyone needs it, I'll post it.

------------------------------------------------------------

#!perl
use File::Sort qw(sortFile);
use File::Sort2	qw(sortFile2);

sortFile( "summary1.tab", "temp.tab");				#sort file
for date

open (IN, "temp.tab");
open (TEMP, ">temp2.tab");
open (OUT, "done.tab");

chomp ($in = <IN>);
@tag = split/\t/,$in;
	#create tag
$output[0] = $in;
		#copy first line to output

while (<IN>) {
	chomp;
	split/\t/;
			#split new line for tag check
	if ($_[1] ne $tag[1]) {
		for $now (@output) {
			print TEMP "$now\n";
	#if it's not the same, print all of output
		}
		undef @output;
		#rid the memory of output
		$output[0] = $_;
	#start an new output with the record we're on (it's not in the old
one)
		@tag = @_;
		close TEMP;
		sortFile2( "temp2.tab", "temp2.tab" );		#sort temp
for ID
		open (TEMPIN, "temp2.tab");
	#open it back up
		while (<TEMPIN>) {
			chomp;
			print OUT "$_\n";
		#print the newly sorted temp file (by date, then ID) to the
output file
		}
		close TEMPIN;
		open (TEMP, ">temp2.tab");
	}else{
		chomp;
		push(@output,$_);
	}
}
close OUT;
close TEMP;


-----------------------------------------------

Thanks for any help,
- Strider




  - I hope you recognize what you're looking for when you find it.



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch