in reply to When hashes aren't enough
You can use references to store any concievable kind of data structure in perl.
### INIT pragma use strict; use warnings; ### INIT vars my $data_root = {}; $data_root->{car} = { wheels => 4, doors => 4, color => 'blue', }; $data_root->{bike} = { wheels => 2, doors => undef, color => 'blue', }; ### DISPLAY print $data_root->{car}{color}; print "\n---------------------\n"; print $data_root->{bike}{color}; print "\n---------------------\n"; print $data_root->{$_}{wheels},"wheels "foreach(keys %{$data_root} +); print "\n---------------------\n";
Am I treading so close to OOP that I just need to take the plunge now?It depends on what you intend to do. Are you storing this data to keep an inventory database of merchandise? Are you creating a structured entity with properties (eg print $color{car}) and methods (eg $car->drive('50mph') )? Are you rolling your own format for an initialization file? Are you ever going to need more than one 'car' or 'bike'? Are you ever going to need nested data (eg a car with a bike in the trunk)?
OOP may not even be relevant if you are simply looking for a way to store some text data.
You can always search on CPAN, you may find something that already fits the bill perfectly. Also, by examining someone else's approach to your goal, you will discover answers to question you hadn't even considered yet. All in all, it is a great way to learn new stuff.
|
|---|