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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-28 07:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found