#!/usr/bin/perl -w # overlay.pl - Don Yang (uguu.org) # # 2014-03-16 use strict; die "$0 \n" unless $#ARGV == 1; sub LoadFile($) { my ($filename) = @_; my @lines = (); if( $filename eq "-" ) { @lines = ; } else { open my $file, "<$filename" or die $!; @lines = <$file>; close $file; } chomp foreach @lines; return @lines; } my @bg = LoadFile($ARGV[0]); my @overlay = LoadFile($ARGV[1]); for(my $y = 0; $y <= $#bg; $y++) { if( $y >= scalar @overlay ) { print $bg[$y], "\n"; next; } for(my $x = 0; $x < length($bg[$y]); $x++) { if( $x >= length($overlay[$y]) ) { print substr($bg[$y], $x); last; } if( substr($bg[$y], $x, 1) =~ /\s/ ) { print substr($overlay[$y], $x, 1); } else { print substr($bg[$y], $x, 1); } } print "\n"; }