Sunday, August 2, 2009

File :aaaabbbbbbcccccccdddddd,File :1111122222333333344444,Find output of file c using interleaving technique.

Example:





Not the most elegant.. but it works, and you'd likely be able to explain how it works to another person.








#!/usr/bin/perl





my $a = "";


my $b = "";





open FILEA, "%26lt;a" or die $!;


open FILEB, "%26lt;b" or die $!;


open FILEC, "%26gt;c" or die $!;





do {


$a = getc(FILEA);


if ( defined $a ) { print FILEC $a; }


$b = getc(FILEB);


if ( defined $b ) { print FILEC $b; }


} while ( defined $a || defined $b );





close FILEA;


close FILEB;


close FILEC;

hydrangea

No comments:

Post a Comment