Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Comment on

( #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

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (7)
    As of 2018-03-17 19:17 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (225 votes). Check out past polls.