Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: %hash (@array && use constant) in Modules

by moodster (Hermit)
on Apr 24, 2002 at 07:30 UTC ( [id://161530]=note: print w/replies, xml ) Need Help??


in reply to %hash (@array && use constant) in Modules

Hashes may not be the fastest way to access data, but they are fast enough for most purposes. I used to be very concerned about performance and speed hits when I started doing perl (it probably comes from when I was trying to do graphics programming for the 286 and every clock cycle counted and certain operations, like division, were feared like the plague). Nowadays I'm more relaxed.

Perl hashes usually gets the job done with the least amount of effort. I use them where I'd use C structs, Java Objects, Vectors, Sets or whatever. They are extremely versatile beasts. It's only when I have ordered data that I have the need for arrays, really. Which leads me to the point I'm trying to make:

For most classes, the members aren't ordered among themselves. In your example, the foo and bar member variables have no real relation to each other and aren't ordered. Since they only exist to hold named pieces of data it makes perfect sense to me to store them in a hash. Of course, there are classes where it'd be more intuitive to use an array but I can't think of a good examle right now. And anyway, if I needed a class to store ordered data, I'd still use a hash and let one of the member variables be a reference to an anonymous array.

Cheers,
--Moodster

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-20 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found