#!/usr/bin/perl -w # merge_text.pl - Don Yang (uguu.org) # # Combine characters from two text files, prefer non-whitespace # characters from the first. use strict; die "$0 \n" unless $#ARGV == 1; my ($handle); open $handle, "< $ARGV[0]" or die $!; my $text1 = join '', <$handle>; close $handle; open $handle, "< $ARGV[1]" or die $!; my $text2 = join '', <$handle>; close $handle; my ($length, $remainder); if( length($text1) <= length($text2) ) { $length = length($text1); $remainder = substr($text2, $length); } else { $length = length($text2); $remainder = substr($text1, $length); } for(my $i = 0; $i < $length; $i++) { my $c = substr($text1, $i, 1); if( $c =~ /\s/s ) { print substr($text2, $i, 1); } else { print $c; } } print $remainder;