in reply to Re: More efficient Data Structure needed
in thread More efficient Data Structure needed

The problem with that is that he isn't doing a one-for-one compare between the two things, he's checking to see if one contains the other (hence the regex). Which make sthe whole problem rather harder.

if ($record->[1] =~ /$data->[0]/) {

Examine what is said, not who speaks.

Replies are listed 'Best First'.
Re: Re: Re: More efficient Data Structure needed
by djantzen (Priest) on Dec 18, 2002 at 02:58 UTC

    Actually that isn't made explicitly clear in the original post, although I agree the absence of anchors certainly indicates that you're correct.

    Tie::Hash::Regex would work in that case, but unfortunately all the efficiency of the hash would be lost as that module simply iterates over the keys in the hash doing a regex match :^\

Re: Re: Re: More efficient Data Structure needed
by iburrell (Chaplain) on Dec 18, 2002 at 17:10 UTC
    If he only needs substring matching, then index is faster and safer than regular expressions. He wouldn't have to worry about escaping characters or compiling the regex.
    if (index($record->[1], $data->[0]) >= 0) {