Emit Code

We desire to be within a HypertextMarkupLanguage tag ($code) nested to a particular level ($depth). We'll stack these codes in an array (@code) so that we can match them as needed later. As a side-effect $code is set non-empty as a contribution to the logic in PrintBodyText.

  sub EmitCode {
    ($code, $depth) = @_;

If we've emitted codes to a depth deeper than desired, then end those outstanding codes.

    while (@code > $depth) 
	{local($_) = pop @code; 
	print "</$_>\n"}

Likewise, if we've yet to emit codes that bring us up to the level we need, then emit the desired code until we get the depth we desire.

    while (@code < $depth) 
	{push (@code, ($code)); 
	print "<$code>\n"}

Now, we're sure to be at the right depth but could still be under the wrong code. If so, end one and start another.

    if ($code[$#code] ne $code)
	{print "</$code[$#code]><$code>\n";
	$code[$#code] = $code;}


Last edited December 18, 1995
Return to WelcomeVisitors