I am somewhat new to Perl, but I have worked with batch files for a long time. I have two programs that I usually call from a batch file. The first sorts data and the second extracts the unique items. I would like to combine these into one script, but I am getting errors when the second OPEN INFILE line is read. I believe this is due to the fact that the first process has not had time to finish the text file that the second one needs. I have attempted to use the sleep and wait lines but have had no success. I have tried to close APPEND; but that did not work either. Can anyone show me what I am doing wrong? Here is what I have. Thank you.
#this file will sort items from a text file
open(INFILE,"print_job_output.txt") || die "Can't open: $!\n";
open(APPEND, ">>sorted_data.txt");
my @words=<INFILE>;
foreach(sort mysort @words) {
print APPEND;
}
sub mysort {
($a) cmp ($b);
}
close(INFILE)
####################################################
##extract the unique ones now
####################################################
open(INFILE,"sorted_data.txt") || die "Can't open: $!\n";
open(APPEND, ">>unique_data.txt");
while($line=<INFILE>){
@line=<INFILE>;
$prev = "not equal to $line[0]";
@out = grep($_ ne $prev && ($prev = $_, 1), @line);
print APPEND @out;
}
close(INFILE)
#this file will sort items from a text file
open(INFILE,"print_job_output.txt") || die "Can't open: $!\n";
open(APPEND, ">>sorted_data.txt");
my @words=<INFILE>;
foreach(sort mysort @words) {
print APPEND;
}
sub mysort {
($a) cmp ($b);
}
close(INFILE)
####################################################
##extract the unique ones now
####################################################
open(INFILE,"sorted_data.txt") || die "Can't open: $!\n";
open(APPEND, ">>unique_data.txt");
while($line=<INFILE>){
@line=<INFILE>;
$prev = "not equal to $line[0]";
@out = grep($_ ne $prev && ($prev = $_, 1), @line);
print APPEND @out;
}
close(INFILE)