Hi Al I'm still a little confused, but it seems that you are as well. Your problem is that you are misunderstanding the distinction between array and scalar variable types. You declare array @newQA but your comment says "holding scalar for the output". You then treat it both as a scalar ( @newQA .= "\n\n" ) and as an array ( @newQA= unshift @newQA, " " ). My best guess is that you're trying to use @newQA as an array of output text lines but I'm not sure.
Your final lines: open @newQA, >> $fileOut; close @newQA; are also way off. Again, my guess is that you're trying to output the text lines in the array to a file, but the first parameter of open (and close) is a file handle. This is probably what you mean: open RESULT, ">> qa.txt"; print RESULT foreach @newQA; close RESULT; but even then I'm not sure you really want to append to an existing file (which is what >> does), and anyway getting this right won't help until you've got the right stuff in your array in the first place. I think you need to give us an example of your data, and what sort of thing you expect in your main variables while the foreach loop is running. By the way, unless you specifically want all of your input in memory at once, I would write: open INFO, "qa.db"; while $line (<INFO>) { : } close INFO; which is both neater and more memory-efficient. Cheers, Rob "Al Lukaszewski" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Greetings, > > It seems my earlier post ['foreach' and error diagnosis] was not clear > enough for some people on list. I will therefore clarify what I am > trying to do and appeal for further assistance. > > I have a grammatical database in a comma-delimited file. The first > field is the line reference. The second field is the form/word which > is described in the other fields. I need to concatenate these words > into lines that are marked by line reference. The output of the > program should be a single text file with each line clearly marked and > two spaces between each text. > > After heeding some of the help I received earlier, I am receiving > other, but fewer, errors. The code I am running and the error output > is posted below. I do not know what a private array is and do not > what is wrong with my concatenation method. Thanks for any help. > > Al L. > > > > *[OUTPUT]* > > Can't modify private array in concatenation (.) or string at ./chgr.pl line 45, near ""\n\n";" > Execution of ./chgr.pl aborted due to compilation errors. > > > > > *[PROGRAM]* > > #!/usr/bin/perl > # > # Read in the data file > # > > use strict; > use warnings; > #use CSV; > > my $file; > $file = 'qa.db' ; # Name the file > open(INFO, "$file" ) ; # Open the file > my @db; > @db = <INFO> ; # Read it into an array > close(INFO) ; # Close the file > > # Initialize scalars > my $line; # = scalar by which program steps through data > my $fieldRef; # = holding scalar for line reference field > my $fieldForm; # = holding scalar for the lemma field > my $fieldMorph; # = holding scalar for the parsing field > my $fieldSynt; # = holding scalar for the syntax field > my $fieldLex; # = holding scalar for the lexical information field > > my @newQA = ""; # = holding scalar for the output, the contents of this scalar will be the compiled texts and will be written to the output file > > my @field; > > my $fieldEval; > my $fieldCtrl = "null"; # Preset control variable to 'zero' > > > > foreach $line (@db) # Assign the contents of @db to $line one line at time for evaluation. > { > chomp ($line); > > # @field = split /,/, $line; > ($fieldRef, $fieldForm, $fieldMorph, $fieldSynt, $fieldLex) = split /,/, $line;#($field[0], $field[1], $field[2], $field[3], $field[4]); > > $fieldEval = $fieldRef; # Assign current line reference to evaluation scalar > > if ($fieldEval ne $fieldCtrl) # If the evaluation scalar and control scalar are not equal, do the following: > { > @newQA .= "\n\n"; # First append two new lines to the output scalar; > @newQA .= $fieldRef; # then, append the new line reference for the fields to come > > $fieldCtrl = $fieldRef; # Assign the new line reference to the control scalar > } > > > @newQA= unshift @newQA, " "; > @newQA = unshift @newQA, $fieldForm; > > > } > > > my $fileOut; > $fileOut = "qa.txt"; > open @newQA, >> $fileOut; > close @newQA; # Close the file > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]