#!/usr/bin/perl -w # mix.pl - Don Yang (uguu.org) # # For each character in background file, mix in non-whitespace characters # from overlay. # # 11/27/11 use strict; die "$0 \n" unless $#ARGV == 1; # Load input my @background; if( $ARGV[0] eq "-" ) { push @background, $_ foreach ; } else { open my $file, "< $ARGV[0]" or die $!; @background = <$file>; close $file; } chomp foreach @background; my @overlay; if( $ARGV[1] eq "-" ) { push @overlay, $_ foreach ; } else { open my $file, "< $ARGV[1]" or die $!; @overlay = <$file>; close $file; } chomp foreach @overlay; # Mix inputs for(my $i = 0; $i <= $#background; $i++) { if( $i > $#overlay ) { print $background[$i], "\n"; next; } for(my $j = 0; $j < length($background[$i]); $j++) { if( $j < length($overlay[$i]) && substr($overlay[$i], $j, 1) !~ /\s/s ) { print substr($overlay[$i], $j, 1); } else { print substr($background[$i], $j, 1); } } print "\n"; }