develooper Front page | perl.beginners | Postings from December 2002

until/if and private array errors

Thread Next
Al Lukaszewski
December 21, 2002 07:29
until/if and private array errors
Message ID:

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.


Can't modify private array in concatenation (.) or string at ./ line 45, near ""\n\n";"
Execution of ./ aborted due to compilation errors.


# 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

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About