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;
In reply to Re: help with search and match
by fruiture
in thread help with search and match
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |