#!/bin/sh -- # This comment tells perl not to loop! eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0; use English; $OUTPUT_AUTOFLUSH = 1; # Don't buffer stdout #----------------------------------------------------- # HABASH Sat Feb 7 16:11:54 EST 2004 # interleave.pl # = (AABB|BBAA|ABAB|BABA) #----------------------------------------------------- $argc = @ARGV; if ($argc != 3) {die("Usage: $0 \n = (AABB|BBAA|ABAB|BABA)\n");} $fileA = $ARGV[0]; $fileB = $ARGV[1]; $pattern = $ARGV[2]; unless (open(A,$fileA)) { die ("Cannot open input file $fileA"); } unless (open(B,$fileB)) { die ("Cannot open input file $fileB"); } unless ($pattern=~/^(AABB|BBAA|ABAB|BABA)$/) { die ("Unrecognized Pattern $pattern"); } @header=@footer=@A=@B=@combo=(); while ($line=){ if ($line=~/^\@/) {@header = (@header , $line)} if ($line=~/^\[/) {@A = (@A , $line)} if ($line=~/^\(/) {@footer = (@footer , $line)} } while ($line=){ if ($line=~/^\[/) {@B = (@B , $line)} } close(A); close(B); if ($pattern=~/^AABB/){ @combo=(@A,@B);} elsif ($pattern=~/^BBAA/){ @combo=(@B,@A);} else { for ($i=0;(($i<@A)||($i<@B));$i++){ if ($pattern=~/^ABAB/){ @combo=(@combo, $A[$i] , $B[$i])} else { #pattern = BABA @combo=(@combo, $B[$i] , $A[$i])} } } foreach $h (@header){ print $h; } print "\n"; foreach $c (@combo){ print $c; } foreach $f (@footer){ print $f; }