Short Answer

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";

Long Answer: what is your goal

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.

See what else is already out there

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.


In reply to Re: When hashes aren't enough by dimar
in thread When hashes aren't enough by Sprad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.