So this would be a very open method:
#!/usr/bin/perl use strict; use warnings; my $base = shift or die; my $cmpdepth = 2; my %base = (); { open my $fh ,'<',$base or die "opening '$base' failed: $!"; while(defined(local $_=<$fh>)){chomp; my $c = \%base; for(split){ $c = ($c->{$_} = {}); } } close $fh; } while(defined(local $_ =<>)){chomp; my @s = split; my $f = 1; my $c = \%base; for( 0 .. ($cmpdepth - 1) ){ $f-- and last unless exists $c->{ $s[$_] } and $c = $c->{$s[$_]}; } print "$_\n" if $f; }
that gives the possibility to check up to any number of fields.
--In reply to Re[5]: help with search and match
by fruiture
in thread help with search and match
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |