Greetings all,
This is my first production Perl script, and I'm having some trouble with nested while loops. I'm hoping that someone here can point me in the right direction. I'm using the script to merge two files and create a third. The first is a delimited text export from a DB, the second is a list of XML fields, and the intended output is an XML file. Simple, right? Well, at the moment I have two problems. If I use "warnings", the script produces the following error: "Use of uninitialized value in concatenation (.) or string at line 28, (SCHEMAIN) line 62" It does produce output, but not as I expected, which is the second issue. The script processes one line of the input correctly, but then stops, apparently dying after one iteration of the second while loop. I imagine this problem involves the declaration/redec of $_, but I just can't figure out why this can't work. Anyone have any ideas as to what's wrong and how I might fix it? Here are my system vitals: Win32 ActiveState ActivePerl 5.6.1.631 I appreciate any help the wizards can offer. Rob #!/usr/bin/perl use strict; use warnings; my $datafile = $ARGV[0]; # read 1st argument into variable $datafile my $schemafile = $ARGV[1]; # etc. my $outputfile = $ARGV[2]; # etc. open (DATAIN,"$datafile"); # open file named by $datafile for reading open (SCHEMAIN,"$schemafile"); # open file named by $schemafile for reading open (XMLOUT, ">>$outputfile"); # open file named by $outputfile for writing (appending) print XMLOUT "<substance>\n"; # print opening substance tag to outputfile while (<DATAIN>) { chomp; my @data = split (/~/,$_); # read line from file called by DATAIN into array @data; assign elements split by "~" character my $count = 0; while (<SCHEMAIN>) { # read one line of schemafile to $_ while lines are available to read my $length = @data; # assign the number of array elements to variable $length my $newelement = $_; # assign the current line of input from schemafile to variable $newelement $newelement =~ s/>a/>$data[$count]/; # search for ">a" in current line; replace with ">" and a single element from the array @data chomp ($newelement); print XMLOUT "$newelement\n"; # write new line of text to outputfile $count++; # increment variable $count } } print XMLOUT "</substance>\n"; # print closing substance tag and newline to outputfile close (XMLOUT); close (SCHEMAIN); close (DATAIN); print "datafile = $datafile and schemafile = $schemafile and outputfile = $outputfile"; ____________ Rob Diethorn Systems Administrator McDonough Braungart Design Chemistry, LLC -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]