in reply to Re: Printing out multiple array lists and more!
in thread Printing out multiple array lists and more!
Code for reference:
My only question is: In lines 36-41 you have a snippet scalar shift @array. What is this doing? :) Thank you very much!!1 #!/usr/local/bin/perl 2 3 use strict; 4 5 my $max = 0; 6 7 sub readfile { 8 my $fn=shift; 9 my @ar; 10 11 open IN,"<$fn" || die "Couldn't open '$fn': $!"; 12 ## snarf the header 13 scalar <IN>; 14 ## read the rest 15 while (<IN>) { 16 chomp; 17 push @ar,$_; 18 $max = $_ if $_ > $max; 19 } 20 close IN; 21 22 @ar; 23 } 24 25 26 ## load the files into arrays 27 my @a=readfile 'f1.lst'; 28 my @b=readfile 'f2.lst'; 29 my @c=readfile 'f3.lst'; 30 31 ## iterate until all arrays are empty 32 for (my $i = 0; $i <= $max; $i++) 33 { 34 next unless $a[0] == $i || $b[0] == $i || $c[0] == $i; 35 36 ## print them out (if they match) 37 printf "%5s", $a[0]==$i ? scalar shift @a : undef; 38 print " | "; 39 printf "%5s", $b[0]==$i ? scalar shift @b : undef; 40 print " | "; 41 printf "%5s", $c[0]==$i ? scalar shift @c : undef; 42 43 print "\n"; 44 }
----------
- Jim
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Printing out multiple array lists and more!
by mr.nick (Chaplain) on May 17, 2001 at 22:08 UTC |