Index: trunk/ippScripts/scripts/ipp_serial_register.pl
===================================================================
--- trunk/ippScripts/scripts/ipp_serial_register.pl	(revision 12617)
+++ trunk/ippScripts/scripts/ipp_serial_register.pl	(revision 12636)
@@ -35,5 +35,4 @@
 
 # Phase 0 imfile processing
-my $list;
 {
     my $command = "$regtool -pendingimfile -dbname $dbname"; # Command to run
@@ -41,19 +40,35 @@
 	run( command => $command, verbose => 1 );
     die "Unable to get phase 0 imfile list: $error_code\n" if not $success;
-    $list = parse_md_list( $mdcParser->parse( join( '', @$stdout_buf ) ) ) or
-	die "Unable to parse output from regtool.\n";
-}
 
-foreach my $item (@$list) {
-    my $exp_tag = $item->{exp_tag};
-    my $class = $item->{class};
-    my $class_id = $item->{class_id};
-    my $uri = $item->{uri};
-    
-    my $command = "$register_imfile --exp_tag $exp_tag --class $class --class_id $class_id --uri $uri --dbname $dbname";
-    $command .= " --workdir $workdir" if defined $workdir;
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run( command => $command, verbose => 1 );
-    die "Unable to do phase 0 imfile processing on $exp_tag $class_id: $error_code\n" if not $success;
+    my @whole = split /\n/, join( '', @$stdout_buf );
+    my @single = ();
+
+    while ( scalar @whole > 0 ) {
+	my $value = shift @whole;
+	push @single, $value;
+	if ($value =~ /^\s*END\s*$/) {
+	    push @single, "\n";
+
+	    my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) ) or
+		die "Unable to parse output from regtool.\n";
+
+	    foreach my $item (@$list) {
+		my $exp_tag = $item->{exp_tag};
+		my $class = $item->{class};
+		my $class_id = $item->{class_id};
+		my $uri = $item->{uri};
+		
+		my $command = "$register_imfile --exp_tag $exp_tag --class $class --class_id $class_id --uri $uri --dbname $dbname";
+		$command .= " --workdir $workdir" if defined $workdir;
+		my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+		    run( command => $command, verbose => 1 );
+		die "Unable to do phase 0 imfile processing on $exp_tag $class_id: $error_code\n" if not $success;
+	    }
+
+
+	    @single = ();
+
+	}	
+    }
 }
 
@@ -64,17 +79,33 @@
 	run( command => $command, verbose => 1 );
     die "Unable to get phase 0 exposure list: $error_code\n" if not $success;
-    $list = parse_md_list( $mdcParser->parse( join( '', @$stdout_buf ) ) ) or
-	die "Unable to parse output from regtool.\n";
+
+    my @whole = split /\n/, join( '', @$stdout_buf );
+    my @single = ();
+
+    while ( scalar @whole > 0 ) {
+	my $value = shift @whole;
+	push @single, $value;
+	if ($value =~ /^\s*END\s*$/) {
+	    push @single, "\n";
+
+	    my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) ) or
+		die "Unable to parse output from regtool.\n";
+
+	    foreach my $item (@$list) {
+		my $exp_tag = $item->{exp_tag};
+		
+		my $command = "$register_exp --exp_tag $exp_tag --dbname $dbname";
+		$command .= " --workdir $workdir" if defined $workdir;
+		my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+		    run( command => $command, verbose => 1 );
+		die "Unable to do phase 0 exposure processing on $exp_tag: $error_code\n" if not $success;
+	    }
+
+	    @single = ();
+
+	}	
+    }
 }
 
-foreach my $item (@$list) {
-    my $exp_tag = $item->{exp_tag};
-    
-    my $command = "$register_exp --exp_tag $exp_tag --dbname $dbname";
-    $command .= " --workdir $workdir" if defined $workdir;
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run( command => $command, verbose => 1 );
-    die "Unable to do phase 0 exposure processing on $exp_tag: $error_code\n" if not $success;
-}
 
 END {
