in reply to Tie::Hash::Regex

I'd automatically qr the "key" if it's not already in the hash.
sub FETCH { my ($self, $key) = @_; my $is_re = (ref($key) eq 'Regexp'); return $self->{$key} if !$is_re and exists $self->{$key}; $key = qr/$key/ if !$is_re; if (wantarray) { return @{$self}{ grep /$key/, keys %$self }; } else { /$key/ and return $self->{$_} for keys %$self; } }


japhy -- Perl and Regex Hacker

Replies are listed 'Best First'.
Re: Re: Tie::Hash::Regex
by davorg (Chancellor) on May 11, 2001 at 19:50 UTC

    Thanks for your excellent suggestions. I can see this making it on to CPAN by the end of the weekend :)

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

Re: Re: Tie::Hash::Regex
by davorg (Chancellor) on May 24, 2001 at 22:22 UTC