in reply to help with search and match
One of the main reasons for Perl's power are it's hashes.
--#!/usr/bin/perl use strict; use warnings; @ARGV >= 2 or die "2 args mandatory"; my ($base,$compare) = @ARGV; # always use smaller file as 'base': #UPDATE: this makes only sense if # the name field is unique in both files! #- thanks to [John M. Dlugosz] ## ($base,$compare) = ($compare,$base) ## if -s $base > -s $compare; open my $basefh,'<',$base or die "opening '$base' failed: $!"; my %base = (); while(<$basefh>){chomp; my ($name,@columns) = split; $base{$name} = \@columns; } close $basefh; open my $cmpfh,'<',$compare or die "opening '$compare' failed: $!"; while(<$cmpfh>){chomp; my ($name,@columns) = split; next unless exists $base{$name}; print "$_ [@{$base{$name}}]\n" if $base{$name}[0] == $columns[0]; } close $cmpfh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: help with search and match
by John M. Dlugosz (Monsignor) on Aug 26, 2002 at 18:47 UTC | |
by fruiture (Curate) on Aug 26, 2002 at 18:50 UTC | |
by John M. Dlugosz (Monsignor) on Aug 26, 2002 at 21:36 UTC | |
by fruiture (Curate) on Aug 26, 2002 at 21:51 UTC | |
by John M. Dlugosz (Monsignor) on Aug 27, 2002 at 14:37 UTC | |
|