bva@cruzio.com (Bruce Van Allen) wrote: >At 8:45 AM +0000 9/5/99, Bart Lateur wrote: >> local $" = "\t"; # why not? >> while(<FILE>) { >> chomp; >> my @field = split /\t/; >> if("@field[2,4,7]" =~ /searchterm/) { >> print "Got a match in $_\n"; >> # prints record >> } >> } >[snip] > >That's zippy, but I'd prefer to use Perl's grep, although it means >slurping in the whole file, which can cost performance-wise if the >file is large. You could split the difference (so to speak): while(<FILE>) { chomp; if( grep {/searchterm/} (split /\t/)[2,4,7] ) { print "Got a match in $_\n"; } } That avoids making the temporary @field (programmable gate?) array, and avoids the unnecessary string interpolation stuff. >Now, if you were searching your database for records with a certain >zip, they'd only appear in the 7th column. You'd get bogus returns if >your method allows the seachterm to match data in any other column. I got the impression that this was for a keyword search, the target term could be in any column. ------------------- ------------------- Ken Williams Last Bastion of Euclidity ken@forum.swarthmore.edu The Math Forum ===== Want to unsubscribe from this list? ===== Send mail with body "unsubscribe" to macperl-request@macperl.org