Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Tie::Hash::Regex

by japhy (Canon)
on May 11, 2001 at 18:07 UTC ( [id://79716]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://79716]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2024-04-19 16:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found