use constant { NAME=>0, TYPE=>1, DETAILS=>2 };
open OUT, ">${new_file}.meta" or die "DIAF OUT: $!";
for( my $page = 0; $page < @meta; ++$page ) {
for( my $line = 0; $line < @{ $meta[ $page ] }; ++$line ) {
print "$page:$line/",scalar @{ $meta[ $page ] },"\n";
## while the NAME is defined
## and neither TYPE nor DETAILS are
while( $meta[ $page ][ $line +1 ][ NAME ]
and ! $meta[ $page ][ $line +1 ][ TYPE ]
and ! $meta[ $page ][ $line +1 ][ DETAILS ]
) {
print "while loop #1\n";
## Concatenate the NAME from the next line
## to the current line
$meta[ $page ][ $line ][ NAME ] .=
' ' . $meta[ $page ][ $line +1 ][ NAME ];
## and delete the next line
splice @{ $meta[ $page ] }, $line +1, 1;
}
## while TYPE is undefined, but DETAILS are
## and there is another line in this page
while( ! $meta[ $page ][ $line +1 ][ TYPE ]
and $meta[ $page ][ $line +1 ][ DETAILS ]
and $line +1 < @{ $meta[ $page ] }
) {
print "while loop #2\n";
## Concatenate the NAME from the next line
## to the current if it exists
$meta[ $page ][ $line ][ NAME ] .=
' ' . $meta[ $page ][ $line +1 ][ NAME ]
if $meta[ $page ][ $line +1 ][ NAME ];
## concatenate the details from the next line
## to the current
$meta[ $page ][ $line ][ DETAILS ] .=
' ' . $meta[ $page ][ $line +1 ][ DETAILS ];
## and delete the next line
splice @{ $meta[ $page ] }, $line +1, 1;
}
## if the next line is undefined
if( ! $meta[ $page ][ $line +1 ] ) {
print "last if check\n";
## while the first line of the next page
## has no TYPE but does have DETAILS
while( ! $meta[ $page +1 ][ 0 ][ TYPE ]
and $meta[ $page +1 ][ 0 ][ DETAILS ]
) {
print "while loop #3\n";
## concatenate the NAMEs if it exists
## in the first line of the next page
$meta[ $page ][ $line ][ NAME ] .=
$meta[ $page +1 ][ 0 ][ NAME ]
if $meta[ $page +1 ][ 0 ][ NAME ];
## And the DETAILS
$meta[ $page ][ $line ][ DETAILS ] .=
$meta[ $page +1 ][ 0 ][ DETAILS ];
## And delete the first line of the next page
splice @{ $meta[ $page +1 ] }, 0, 1;
}
}
print OUT join( "\t",
@{ $meta[ $page ][ $line ] }[ NAME, TYPE, DETAILS ]
), "\n";
}
}
close OUT;
####
## while TYPE is undefined, but DETAILS are
## and there is another line in this page
while( ! $meta[ $page ][ $line +1 ][ TYPE ]
and $meta[ $page ][ $line +1 ][ DETAILS ]
and $line +1 < @{ $meta[ $page ] }
) {
####
## while there is another line in this page
## and its TYPE is undefined, but its DETAILS are
while( $line +1 < @{ $meta[ $page ] }
and ! $meta[ $page ][ $line +1 ][ TYPE ]
and $meta[ $page ][ $line +1 ][ DETAILS ]
) {