Hi Al OK I'm being lazy again, this time partly because you are in a hurry. The following code works with your dataset. You were badly misunderstanding arrays - I've taken out all of them!
Let me know if you need anything explaining. Cheers, and good luck. Rob #!/usr/bin/perl ############################################################# ############################################################# # A PROGRAM TO READ THE QUMRAN ARAMAIC DATABASE # # AND CONCATENATE IT BY TEXT NAME INTO # # NUMBERED LINES, PROPERLY FORMATTED FOR A CHRESTOMATHY # ############################################################# ############################################################# #use strict; #use warnings; ################################### # OPEN THE INPUT AND OUTPUT FILES # ################################### my $file; $file = '4Q246.db' ; # Name the input file open(INFO, "$file" ) or die"Cannot open $file:$!\n"; # Open the input file or report failure #my @db; #@db = <INfo> ; # Read it into an array #close(INFO) ; # Close the input file open OUT, ">>qa.txt" or die "Cannot open file 'qa.txt'!\n"; # Open the output file ####################################################### # FOREACH CONTROL TO READ THE INPUT FILE LINE BY LINE # # AND MANIPULATE THE DESIRED DATE TO AN OUTPUT FILE # ####################################################### my $fieldEval; my $lineOut; foreach my $line (<INFO>) { chomp $line; next unless $line; # ignore blank records ($fieldRef, $fieldForm) = split /,\s*/, $line; # If the reference has changed then output the data for # the previous reference, if any; set the new reference # into the line buffer; and update the current reference # if ($fieldRef ne $fieldEval) { print OUT "$lineOut\n" if $lineOut; $lineOut = " $fieldRef"; $fieldEval = $fieldRef; } # Add the lemma field to the begging of the output line # $lineOut = "$fieldForm $lineOut"; } # Make sure the data for the final reference is output # print OUT "$lineOut\n" if $lineOut; close OUT; close INFO; ----- Original Message ----- From: "Albert L. Lukaszewski" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Saturday, December 21, 2002 5:20 PM Subject: Re: until/if and private array errors > Thank, again, for your help. I have reworked the program to be > (hopefully) a bit neater and leaner. In the following I will give you > a sample of my data, a sample of the desired output, and my program as > it stands now. > > I am using "4Q246.db" as a sample of the larger file. In between each > text, I want it to add three CRs, two blank lines, between the end of > the one text and the title of the next. Ultimately, I would love it > if they could all go into files according to their names, but I am > pressed for time and just need them collated for right now. > > Thanks. Any help appreciated. > > al > > > > > DATA: > > 4Q246.1.1, yhwl[(], prep.|s5, prep.loc~, > 4Q246.1.1, tr#, v-G11, v., <yr# to settle/rest > 4Q246.1.1, lpn, v-G10, v., <lpn to fall > 4Q246.1.1, Mdq, prep., prep.locative, <Mdq before > 4Q246.1.1, )ysrk, n-mse, p.obj., <)srk chair/throne > > 4Q246.1.2, )kl[m], n-mse, vocative, <Klm king > 4Q246.1.2, )ml(<m>[l], prep.|n-mse, prep.temporal|p.obj., <Ml( forever/everlasting > 4Q246.1.2, ht), p2, s., > 4Q246.1.2, zgr, adj-msa, adj.modifier, <zgr angry/distressed > 4Q246.1.2, Kyn#w, c.conj.|n-mpc|s2, s., <yn# year > > 4Q246.1.3, ...,, , > 4Q246.1.3, Kwzx, n-msc|s2, , <wzx vision nb-the waw is likely to be a yod > 4Q246.1.3, )lkw, c.conj.|adj-mse, adj.substantive, > 4Q246.1.3, ht), p2, s., nb-Puech reads as subject but Fitz reads as participle; however participle must be consonant with its noun > 4Q246.1.3, d(, prep., prep.temporal, > 4Q246.1.3, )ml(, n-mse, p.obj., <Ml( forever > > > > > > OUTPUT (right justified eventually): > > )ysrk Mdq lpn tr# yhwl[(] 4Q246.1.1 > Kyn#w zgr ht) )ml(<m>[l] )kl[m] 4Q246.1.2, > )ml( d( ht) )lkw Kwzx ... 4Q246.1.3 > > > > > PROGRAM: > > #!/usr/bin/perl > > ############################################################# > ############################################################# > # A PROGRAM TO READ THE QUMRAN ARAMAIC DATABASE # > # AND CONCATENATE IT BY TEXT NAME INTO # > # NUMBERED LINES, PROPERLY FORMATTED FOR A CHRESTOMATHY # > ############################################################# > ############################################################# > > #use strict; > #use warnings; > > ################################### > # OPEN THE INPUT AND OUTPUT FILES # > ################################### > > my $file; > $file = '4Q246.db' ; # Name the input file > open(INFO, "$file" ) or die"Cannot open $file:$!\n"; # Open the input file or report failure > #my @db; > #@db = <INfo> ; # Read it into an array > #close(INFO) ; # Close the input file > open OUT, ">>qa.txt" or die "Cannot open file 'qa.txt'!\n"; # Open the output file > > ######################################## > # INITIALIZATION OF SCALARS AND ARRAYS # > ######################################## > > my $line; # = scalar by which program steps through data > my $fieldEval = "null"; # = holding scalar for evaluating whether the line reference has changed > my $fieldCtrl = "null"; # Preset scalar to 'zero' for evaluating whether the line reference has changed > > my @field; > #my @outbound = ""; # = holding array for output of line - but not line reference > > my $lineOutCounter; # counter for how many times a value is added to @lineOut > > ####################################################### > # FOREACH CONTROL TO READ THE INPUT FILE LINE BY LINE # > # AND MANIPULATE THE DESIRED DATE TO AN OUTPUT FILE # > ####################################################### > > foreach $line (<INFO>) { # Assign the contents of the input file to $line one line at time for evaluation. > chomp ($line); > my @lineOut = ""; # = holding array to which forms will be appended right to left > > @field[0..4] = split /,/, $line; # Read each line as five fields split by commas > > $fieldEval = @field[0]; # Place/Copy line reference into evaluation scalar > > print "@field[0] \t @field[1] \t $fieldEval \t @lineOut\n"; > > if ($fieldCtrl ne $fieldEval){ # Evaluate whether line reference has changed > $fieldCtrl = @field[0]; # IF SO, assign the new line reference to the control scalar > > printf OUT "\n\n\n"; # Print 3 carrige returns to output file - this will result in two blank lines > printf OUT " ", @field[0]; # Print tabspace and the new line reference > > @lineOut eq @field[1]; > print "\t @lineOut \t @field\n"; > } > > else > { > foreach $word ($line){ > @lineOut = unshift @lineOut, " "; # Append a blank space to the beginning of lineOut > @lineOut = unshift @lineOut, @field[1]; # Append the form of the current line to the beginning of lineOut > $lineOutCounter = $lineOutCounter + 1; ##### > } > } > > # print "@lineOut"; ##### > > printf OUT "@lineOut \n"; # Print the lineOut array to the output file > } > > #print "\n @field \n"; > close (OUT); # Close the output file > close(INFO) ; # Close the input file > __END__ > > > -- > > Albert Lukaszewski > University of Saint Andrews > Saint Andrews, Fife > KY16 9JU > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]