<?xml version="1.0" encoding="windows-1252"?>
<node id="36523" title="having difficulty getting $self back from an _init() function" created="2000-10-12 22:07:41" updated="2005-08-12 20:42:06">
<type id="1857">
categorized question</type>
<author id="11732">
QandAEditors</author>
<data>
<field name="doctext">
I'm working on an object that is complex enough (using XML::Parser to initialize the object) that I broke the initialization into a separate function from the constructor.  I've put the initialization function into a block with some package variables and private functions something like this:

&lt;pre&gt;
sub new
{
  my $self = {};
  bless $self, shift;
  $self-&gt;_init();

  return $self;
}

{
  my(%registry,%regattrs)
  ...

  sub _parseStart
  sub _parseEnd
  ...

  sub _init()
  {
    $self = shift;

    parse file....

    $self = { 'modules' =&gt; { %registry },
              'site'    =&gt; $regattrs{site}
            };
  }

}
&lt;/pre&gt;

The problem is that upon returning from init back in the constructor, $self doesn't seem to be referring to anything anymore, even though i know it's been assigned properly (tested to see if the content was there before exiting _init - it was).  Am i having scoping issues?

This isn't the first time I've done something like this, but I had no difficulties last time.

Thanks much,

Stephen</field>
<field name="parent_node">
1838</field>
<field name="reputation">
3</field>
</data>
</node>
