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).#!/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"; }
In reply to Re: Printing out multiple array lists and more!
by mr.nick
in thread Printing out multiple array lists and more!
by snafu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |