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

Re^2: Re-orderable keyed access structure?

by nothingmuch (Priest)
on Aug 14, 2004 at 08:03 UTC ( #382946=note: print w/replies, xml ) Need Help??


in reply to Re: Re-orderable keyed access structure?
in thread Re-orderable keyed access structure?

You could also wrap this in a native interface:
my $obj = new BrowserUKStruct; tie my %hash, "BrowserUKHash", $obj; tie my @array, "BrowserUKArray", $obj;
It should be quite easy, with all the tie methods simply translating.

You'd have to decide on a proper interface though, like is what you set also what you get (is $hash{key} an array reference of index and value?). You could also decide, for simplicities sake that the hash and array interfaces are read only, and modify the object directly.

I think this is a wonderful example of where perl fscking kicks a**. The ability to glue an arbitrary store, like an object, into a hash and array interface, simultaneously is simply superb. Moreover, this is a good example of what tie comes to solve. By giving you the possibility of treating your hash-like and array-like data as real hashes and arrays, you learn a good lesson about the value of abstraction, and polymorphism. Well, I did, at least, when I was obsessed with tie.

-nuffin
zz zZ Z Z #!perl

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2020-02-25 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (108 votes). Check out past polls.

    Notices?