in reply to Globalize the XML writer object

Declare your object as a global variable (let's say your current package is Foo):
package Foo; our $XmlWriterObject = new XML::Writer( DATA_MODE => 1, DATA_INDENT => + 4, OUTPUT => $Output );

So, you can access it from another package (say Bar):

package Bar; $Foo::XmlWriterObject->endTag("Config");

Replies are listed 'Best First'.
Re^2: Globalize the XML writer object
by priyaviswam (Sexton) on Sep 19, 2011 at 10:43 UTC

    Hi, I tried by declaring it as "Our". But the case is : Lets say :

    Package foo sub create xml{ our $XmlWriterObject = new XML::Writer( DATA_MODE => 1, DATA_INDENT => + 4, OUTPUT => $Output ); } package Bar; sub { $Foo::XmlWriterObject->endTag("Config"); }
    For this the xml file is created but no data has been written into it.

    Please clarify.

      priyaviswam:

      After I added use strict and use warnings and corrected the myriad errors, I was able to make it work just fine. I'd post the (trivial) code, but given that you didn't even bother to try to make a working example, despite being here since July, I'm not terribly motivated to cut & paste my working code snippet here.

      A couple hints:

      • Subroutines need names.
      • Case matters.
      • You actually need to *call* subroutines in order for them to do things for you.

      Please make your code at least *compile* first, and then I'll be happy to give you a few more pointers.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.