*laugh* - Thanks for the pointers and consider myself better learned. :) Hmm ... now I better go & hunt down all those greps in my scripts...
Jason If memory serves me right, on Tuesday 29 January 2002 13:26, Jeff 'japhy' Pinyan wrote: > On Jan 29, Jason Purdy said: > >my ( @filea, @fileb, @inAButNotInB, @inBButNotInA ); > > I don't see any hashes being used. This feels like it's going to be very > inefficient. > > >open ( FILEA, shift ) || die "Cannot open 1st file: $!\n"; > >@filea = <FILEA>; > >close ( FILEA ); > > > >open ( FILEB, shift ) || die "Cannot open 2nd file: $!\n"; > >@fileb = <FILEB>; > >close ( FILEB ); > > > >foreach my $object ( @filea ) { > > chomp $object; > > push @inAButNotInB, $object if ( !grep(/$object/, @fileb) ); > > And indeed it is. Do not use grep(/$foo/, LIST) to determine if $foo is > in LIST, for a myriad of reasons. First, you're using a regex, so if $foo > has any regex metacharacters in it, you'll get false negatives and false > positives. Second, you're not anchoring the regex at all, so if LIST > contains "rabbit" and $foo is "bit", you'll get a false positive. Third, > grep() goes through the ENTIRE list. Imagine the consequences of > > if (grep $_ == 5, 1 .. 10_000) { ... } > > You've just scanned 99,995 more elements than necessary! > > The Perl FAQ suggests use of a hash. See my response to this same > question. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]