#!/usr/bin/perl -w
use strict;

use Getopt::Std;
use IO::File;

use vars qw/$opt_d/;

getopts("d:");

$opt_d ||= "\t";

my @files = @ARGV;

for (@files) {
	$_ = $_ eq "-" ? \*STDIN : IO::File->new($_) || die "cannot open file $_\n";
	$_ = [<$_>];
	for (@$_) {chomp};
}

print_cross("", @files);

sub print_cross {
	my ($start, @arys) = @_;
	if (@arys == 0) {
		print substr $start, length $opt_d;
		print "\n";
		return;
	}
	my $ary = shift @arys;
	for (@$ary) {
		print_cross("$start$opt_d$_", @arys);
	}
}
