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

[FWP] COBOL as Perl



After all the bashing of folks that force perl into other languages,
I'd like to put on the table an idiom that I've been using for years.

However, This looks and smells like COBOL.  Can anyone reduce this
template? I only reduce this when the details are filled in. But
someone here may have a better way.

Note, that the hand-waving extract_keys will build up a key from the
appropriate parts or return $high_values when supplied an undef.

	$high_value = "\xff" x 80;	# Or whatever
	
	$left = <LEFT>;
	$left_key = extract_key($left);

	$right = <LEFT>;
	$right_key  = extract_key($right);

	while (1) {
		$key = extract_key();	# Do whatever is needed

		if ($left_key lt $right_key) {
			# use left

			$left = <LEFT>;
			$left_key = extract_key($left);
			next;
		}

		if ($left_key gt $right_key) {
			# use right

			$right = <RIGHT>;
			$right_key = extract_key($right);
			next;
		}

		if ($left_key eq $high_values) {
			last;	# Finished.
		}

		# use both

		$right = <LEFT>;
		$right_key = extract_key($right);
		$left = <LEFT>;
		$left_key = extract_key($right);
	}
		
The only time this failed me was on some stupid release of SunOS or
Solaris where memcmp() and strcmp() violated the manpage and did a
signed comparison.  Luckily, none of my keys ever used \x7f.

<chaim>
-- 
Chaim Frenkel					     Nonlinear Knowledge, Inc.
chaimf@pobox.com				               +1-718-236-0183

==== Want to unsubscribe from Fun With Perl?
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org