Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Tie::Hash::Regex

by Masem (Monsignor)
on May 11, 2001 at 17:22 UTC ( [id://79698]=note: print w/replies, xml ) Need Help??


in reply to Tie::Hash::Regex

My knowledge of ties is somewhat lacking, and I don't know how possible it would be, but could this be modified or adapted such that instead of just the first value who's key matched the regex, could not all values whose keys match the regex be returned in some fashion. I know this wouldn't make sense programmatically for $hash{/./} (the $ implied scalar, but you could return a list ref, but this can easily get messy), but I dunno if it's possible to use something like @hash{/./} to do this. Sure, this is just simply doing the same as @array = map { $hash{$_} if /./ } keys %hash;, but it would seem to compliment the above well.


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

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

    I was just having a very similar conversation with someone in the office about those possibilities. Didn't manage to come to any firm conclusions tho' :(

    One thing we did think of - you could implement the delete function in such a way that it deleted every key that matched the regex (still some problems there tho' - what if the exact key of one element is also part of another key and would therefore match the regex?)

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

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

      Another idea similar to your deleting but without modifying the hash would be to make the fetch function store the current position of where it is in the keys, then subsequent calls would start from that last position. Of course, you'd then need a secondary hash in the tie to keep track of this, and there would be no easy way to reset this short of a function call to trick it. Additionally, modification of the hash between subsequent calls would pose a problem.

      Just tossing out ideas here in case something triggers insight....


      Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-26 03:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found