in reply to Writing in reverse

Untested code follows. It's highly inefficient, but you get the idea:
my (@first, @second); { local *FILE1; local *FILE2; open(FILE1, $file1) || die "Can't open $file1: $!"; open(FILE2, $file2) || die "Can't open $file2: $!"; @first = reverse split(//, <FILE1>); @second = reverse split(//, <FILE2>); close FILE1; close FILE2; } while (@first) { my $couplet = shift @first . shift @second; print "$couplet "; }
A more efficient technique would involve substr and not that yucky reverse split magic, which may not work anyway. (I'm not at a machine where I can test this right now.)

Update: chop is a better solution yet.

Replies are listed 'Best First'.
RE: Re: Writing in reverse
by princepawn (Parson) on Aug 01, 2000 at 16:31 UTC
    @first = reverse split //, <FILE1>;
    will only operate on the first line of the file because split forces the filehandle into a scalar context.