downer has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; my $wantedLines = shift; # number of unique instances wanted my $numFiles = 0; my @files = (); while( my $file = shift) { open $files[$numFiles++], '<', $file or die "can't open $file, $!\ +n"; } my $totalLines = 0; my $ct = 0; my %unique = (); while($totalLines <= $wantedLines) { my $num = $ct++; $num = $num%$numFiles; print "$num\n"; my $this = <$files[$num]>; unless(exists $unique{$this}) { print $this; $totalLines++; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: reading from an arbitrary number of files using anonymous file handles
by JadeNB (Chaplain) on Dec 05, 2008 at 23:21 UTC | |
|
Re: reading from an arbitrary number of files using anonymous file handles
by almut (Canon) on Dec 05, 2008 at 23:30 UTC | |
|
Re: reading from an arbitrary number of files using anonymous file handles
by Perlbotics (Archbishop) on Dec 05, 2008 at 23:40 UTC | |
|
Re: reading from an arbitrary number of files using anonymous file handles
by Not_a_Number (Prior) on Dec 06, 2008 at 00:11 UTC | |
|
Re: reading from an arbitrary number of files using anonymous file handles
by eye (Chaplain) on Dec 06, 2008 at 07:11 UTC |