[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Elementary Question Redux



Still trying to parse a Hypercard text extract with gratuitious Carriage
Returns  with the following script (debugging statements included)

#!perl -w

$iput = "AddressDelimited.txt"; 					#
name the file
$oput = "Report";
	# ditto

open (IN, "<$iput") or die ("Input File '$iput' open failed\n");
open (OUT,">$oput") or die ("Output File '$oput' open failed\n");


$lineCnt = 0;
$leftover = 0;
$saveSeq = "";
#  $saveSeqNum = 0;
$previousLine = "";


#-------- MAIN LOOP --------------------
print ("main loop\n");
while (defined($line = <IN>)) {
			$lineCnt++;

				print OUT ("****** RECORD $lineCnt  READ
**********\n");
    print  ("****** RECORD $lineCnt  READ **********\n");

    @line = split (/XZX/,$line);

      for ($fldNum = 0; $fldNum <= $#line; $fldNum++) {
							    if ($leftover
== 1) {

						brokenLine();

		}


		 elsif (($fldNum == $#line) || ($line =~ m/ZXZ/) ) {

				lastLine();

		}

		else  {


		 print OUT ("Field $fldNum: $line[$fldNum]\n");


		}

      }

				$saveSeq  = chomp($line);    #save line in
case it is incomplete



						#and needs to be
concatenated with subsequent



						#lines


   }

print ("$lineCnt records read \n");
close (IN);
close (OUT);

#----------------------- SUBROUTINES  ------------------------

sub brokenLine {
print("brokenLine\n");
#--- keep putting the field seqments together until we have end-of-record


				if  ( $line[$fldNum] =~ m/ZXZ/ )  {

			@endLine = split(/ZXZ/,$line);

			$leftover = 0;

			$previousLine =  $saveSeg.$endLine[0];

			print OUT ("Field $fldNum: $line[$fldNum]\n");

				}

				else {

			$leftover = 1;

		$previousLine =  $saveSeg.$line;
									}

}


#---------------------------------------------------------------
sub lastLine {
print("lastLine\n");
				if  ($line[$#line]  eq "ZXZ") {

	$saveSeg = $line[$#line];

	$leftover= 0;

							}
							else {

	$leftover = 1;
								 print OUT
("Field $fldNum: $line[$fldNum]\n");

}
		}


************************************
I get the following error messages at run-time from the sub-routine I
called brokenLine from the expression

$previousLine =  $saveSeg.$line;
 ************************************
V
V
V
V




main loop
****** RECORD 1  READ **********
lastLine
****** RECORD 2  READ **********
brokenLine
# Use of uninitialized value, <IN> chunk 2.
File 'DorjeJigje:Programming:MacPerl Ä:Noe's Perl Stuff:addRpt3'; Line 68
****** RECORD 3  READ **********
brokenLine
# Use of uninitialized value, <IN> chunk 3.
File 'DorjeJigje:Programming:MacPerl Ä:Noe's Perl Stuff:addRpt3'; Line 68
****** RECORD 4  READ **********
brokenLine
# Use of uninitialized value, <IN> chunk 4.
File 'DorjeJigje:Programming:MacPerl Ä:Noe's Perl Stuff:addRpt3'; Line 68
brokenLine

etc..... incrementing the chunk number.....

It is probably elementary, but I don't know where to look up the error.   Help!

	Noe

	          \\\
	         (@v@)  W
	          (  O )  //
	            |  | //
	          /  ? |/
	         //     |
	         |||     \
	         M| /\ |
	            ||   ||
	            ||   ||
	            LL  LL
		



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org