#!/usr/bin/perl -w use strict; use Symbol; use Text::Tabs; die("usage: overlay file1 file2\n") unless scalar @ARGV == 2; my @data; for(my $i=0; $i < scalar @ARGV; $i++){ open($data[$i]->{FH}=gensym, $ARGV[$i]) || die("overlay($ARGV[$i]): $!\n"); 1 while(readline(*{$data[$i]->{FH}})); $data[$i]->{LINE} = $.; seek($data[$i]->{FH}, 0, 0); } my $maxline = $data[0]->{LINE} > $data[1]->{LINE} ? $data[0]->{LINE} : $data[1]->{LINE}; for(my $i=0; $i < $maxline; $i++){ if( $i > $data[0]->{LINE} ){ while(readline(*{$data[1]->{FH}})){ print; } last; } elsif( $i > $data[1]->{LINE} ){ while(readline(*{$data[0]->{FH}})){ print; } last; } else{ for my $data (@data){ $data->{str} = readline(*{$data->{FH}}); chomp($data->{str}); $data->{str} = expand($data->{str}); } my $maxchar = length($data[0]->{str}) > length($data[1]->{str}) ? length($data[0]->{str}) : length($data[1]->{str}); my @onechars = split(//, $data[0]->{str}); my @twochars = split(//, $data[1]->{str}); my $str; for(my $j=0; $j<$maxchar; $j++){ if( $j > $#onechars ){ $str .= join('', splice(@twochars, $j)); } elsif($j > $#twochars){ $str .= join('', splice(@onechars, $j)); } else{ $str .= $onechars[$j] eq ' ' ? $twochars[$j] : $onechars[$j]; } } print $str, "\n"; } }