Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

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

To put it another way ... create a hash, each element of which is a reference to, either the object itself, or another hash which contains various references that you need when accessing it.   Thanks to the “auto-vivification” features of Perl, that can be quite easy to do.   For example:

my $objs; $$objs{'widget1'}{'widget'} = $widget1; $$objs{'widget1'}{'object'} = $object1; ...

If in this example $widget1 and $object1 contain references to this-or-that, now the various hash-entries thus created contain another reference to those same things, whose reference-count is now at least 2.   Perl automatically recognized $objs to be a hash, automatically created an element for 'widget1', then automatically caused that element to be another hash, and inserted 'widget' and 'object' elements into that.

Note that the syntax $$objs{'widget1'} is exactly equivalent to $objs->{'widget1'}, as you prefer.

This hashing technique now lets you build an arbitrary directory of entries which allow you to map any name that you receive to everything that you need to know about it.   It also allows you to recognize, through exists(), if you have encountered a name that you have no information about.   There are many, many ways to write this, but the differences are unimportant; the central idea is the same.

(If the search needs to be case-insensitive, simply use lc()to lowercase the string before using it as a hash-key, and likewise ensure that all inserted keys are lowercased.)


In reply to Re: Is it possible to get reference to scalar based on scalar name by sundialsvc4
in thread Is it possible to get reference to scalar based on scalar name by mrider

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 taking refuge in the Monastery: (2)
As of 2024-03-19 06:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found