Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

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

As a "matter arising" from my playing with the above, but of little real import

If my object is internally implemented using a single scalar value, and I use the IOO method of using the blessed ref representing the object as a key into a my'd hash, then I need 3 things. The hash (%hash), the scalar holding my data ($data), and a blessed ref ($self);

package mypackage; my %hash; sub new { my $self = bless \1, $_[0]; $hash{ $self } = 'Initial data'; return $self; }

In the above, I am using \1 just to get a unique scalar ref which I can bless. I'm then using this as the key through which to access another scalar (the hash value) which is going to hold my actual data.

Now (my twisted type of) logic says, if I already have a scalar to hold my data, then I don't need to create another just to get my blessed ref, I could just bless a reference to the data. The problem is, you can't take a reference to a hash element until you have a key, and I want to use the reference as the key. Catch-22

Can I have my chicken lay an egg? Can I generate a self-addressing stringified reference?

The "mypackage=SCALAR()" bit is constant, so I would need to vary the hex value within the brackets until the address of the scalar allocated for the hash generated matched the hex value I generated. Is that possible? In my lifetime:)


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.


In reply to Re: Temporarily disabling overloaded operations. by BrowserUk
in thread Temporarily disabling overloaded operations. by BrowserUk

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 sharing their wisdom with the Monastery: (6)
As of 2024-04-19 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found