in reply to Printing out multiple array lists and more!

I'm almost embarressed to submit this (it's very dirty as far as I can tell), but here is my go:
#!/usr/bin/perl use strict; sub readfile { my $fn=shift; my @ar; open IN,"<$fn" || die "Couldn't open '$fn': $!"; ## snarf the header scalar <IN>; ## read the rest while (<IN>) { chomp; push @ar,$_; } close IN; @ar; } ## load the files into arrays my @a=readfile '1'; my @b=readfile '2'; my @c=readfile '3'; ## iterate until all arrays are empty while (defined @a || defined @b || defined @c) { ## find the lowest value my $s; $s=$a[0] < $b[0] ? $a[0] : $b[0]; $s=$s < $c[0] ? $s: $c[0]; ## print them out (if they match) printf "%5s", $a[0]==$s ? scalar shift @a : undef; print " | "; printf "%5s", $b[0]==$s ? scalar shift @b : undef; print " | "; printf "%5s", $c[0]==$s ? scalar shift @c : undef; print "\n"; }
What i don't like about this: I don't like the selection of the next value (the assignment to $s). It does, however, allow for non-linear data (you can have 1,2,3,4 in one file, 2,3,10 in another and 66 in the third and it will still work).

Replies are listed 'Best First'.
Re: Re: Printing out multiple array lists and more!
by snafu (Chaplain) on May 17, 2001 at 18:39 UTC
    I tried your code as well. Unfortunately, I got no output =P. If you want to work with the lists that I am using click here.

    ----------
    - Jim