[26624] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8734 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 6 00:05:22 2005

Date: Mon, 5 Dec 2005 21:05:04 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 5 Dec 2005     Volume: 10 Number: 8734

Today's topics:
        A simple inheritance question. <DG@nowhere.com>
    Re: A simple inheritance question. <invalid@nowhere.com>
    Re: My experience with XML::DOM VS XML::LibXML <1usa@llenroc.ude.invalid>
        Win32::OLE::GetObj question <ftoewe@austin.rr.com>
    Re: Win32::OLE::GetObj question <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 05 Dec 2005 21:39:39 -0600
From: Don Gatlin <DG@nowhere.com>
Subject: A simple inheritance question.
Message-Id: <11pa20ve8468a0d@corp.supernews.com>

Let me see if I can explain the question in a way to be sensible.
The code is at the bottom.

I build an Object1 and initalise it with some data with new();
I make an instance of it and, using a method in the object,  can get or
change the data.
At this point I can access it from anywhere in main and the data is valid,
including changes and additional keys in the hash %self.
Normal simple OO stuff.

Now it is inheritance time.
I build an Object2 and and inherit the original Object1.  The methods in
both objects work fine, but only the original data exists in Object1 when I
access Object1 from Object2, not changes or additions.   I think I know why
from tracing through the process.  It appears that when I inherit Object1
from Object2, it reinitalises the copy with the start data when it flows
through the Object1->new() process.

Fine.  But how do you inherit an object with all the changes to the data?

I am more interested in understanding the process than fixing the code.

Code Follows 

#!/usr/bin/perl -w

use Class1;
use Class2;

        my $object1 = Class1->new();

#Here the hash in the object contains 
#{NAME} = "Christmas"

        my $returnval= $object1->addakey(); 

#Now the hash in the object contains 
#{NAME} = "Christmas"
#{TYPE} = "Tree"        

        my $object2 = Class2->new();
        print $object2->{NAME}; #OK it exists.
        print $object2->{DATA};         #same
        print $object2->{TYPE}; #HUH? It doesn't in this view of Object1.
        print $object1->{TYPE}; #Still exists here in the original.
        exit;

###########End of program

package Class1;   #this is Class1.pm

sub new
{
        my $class = shift;
        my $self = {};
        $self->{NAME} = "Christmas";
        bless $self, $class;
        return $self;
}

sub addakey {
        my $self = shift;
        $self->{TYPE} = "Tree";   #I know it is hard coded.
}
return 1;

########################
package Class2; #this is Class2.pm

use Class1;
@ISA = qw(Class1);

sub new
{
        my $self = Class1->new();
        $self->{DATA} = 200;
        return $self;
}
return 1;




------------------------------

Date: Mon, 05 Dec 2005 21:55:27 -0600
From: Don Gatlin <invalid@nowhere.com>
Subject: Re: A simple inheritance question.
Message-Id: <pan.2005.12.06.03.55.23.462243@nowhere.com>

On Mon, 05 Dec 2005 21:39:39 -0600, Don Gatlin wrote:

Sorry about the formatting.  The Knode editor sucks big time. Let me try
again on the screwed up part

my $object2 = Class2->new();

print $object2->{NAME};
#OK it exists.

print $object2->{DATA};
# it exists

print $object2->{TYPE};
#HUH? It doesn't in this view of Object1.

print $object1->{TYPE};
#Still exists here in the original.

exit;


------------------------------

Date: Tue, 06 Dec 2005 00:30:32 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: My experience with XML::DOM VS XML::LibXML
Message-Id: <Xns9723C67A640A7asu1cornelledu@127.0.0.1>

Jahagirdar Vijayvithal S <jvs@india.ti.com> wrote in
news:slrndot1va.q1s.jvs@bstclindt008.india.ti.com: 

> I have a script where I am 
> 1> Opening a pipe to a program which reads in a binary file(400MB) and
> dumps out XML data(XXX GB's) (tethereal) 2> Grabing chunk's of data
> within tags <packet>.....</packet> (approx 4 to 20 K)
> 3> parsing the XML 
> 4> post processing based on fields and attributes in the XML document.
> 
> Initially I used XML::DOM and found that my memory consumption
> constantly increased filling up the entire RAM and SWAP space before
> crashing(approx 32GB RAM and 160+ GB Swap consumed).
> Switching to XML:LibXML and replacing the XML::DOM constructs with
> their equivalent I find that my worst case Memory consumption remains
> below 2GB each (RAM and swap) and average is around 50 MB each.
> 
> While my problem is solved I am curious to know wether there is any
> known Issues which caused the above problems?
> 
> code fragment used by me is as below

The answer seems to lie in the documentation:

http://search.cpan.org/~enno/libxml-enno-1.02/lib/XML/Parser/Expat.pod

release

There are data structures used by XML::Parser::Expat that have circular 
references. This means that these structures will never be garbage 
collected unless these references are explicitly broken. Calling this 
method breaks those references (and makes the instance unusable.)

http://search.cpan.org/~enno/libxml-enno-1.02/lib/XML/Parser.pod

DESCRIPTION ^

This module provides ways to parse XML documents. It is built on top of 
XML::Parser::Expat, which is a lower level interface to James Clark's 
expat library. Each call to one of the parsing methods creates a new 
instance of XML::Parser::Expat which is then used to parse the document. 

It looks like the XML::Parser::Expat instances used to parse each chunk 
are not being released. One can see this by running:

Finally:

http://search.cpan.org/~enno/libxml-enno-1.02/lib/XML/DOM.pm

SYNOPSIS ^

# Avoid memory leaks - cleanup circular references for garbage 
collection

 $doc->dispose;

So compare:

#!/usr/bin/perl

use strict;
use warnings;

use XML::DOM;

my $xml = <<EO_XML;
<person>
            <name>John Doe</name>
            <phone>21212121215</phone>
            <address> 75 Rue de Marshall
            Boulevard Attarde
            453 France</address>
</person>
EO_XML

while( 1 ) {
    my $p = XML::DOM::Parser->new;
    $p->parse($xml);
}
__END__

Run this and wait for your computer to run out of memory.

However, add the dispose call:

#!/usr/bin/perl

use strict;
use warnings;

use XML::DOM;

my $xml = <<EO_XML;
<person>
            <name>John Doe</name>
            <phone>21212121215</phone>
            <address> 75 Rue de Marshall
            Boulevard Attarde
            453 France</address>
</person>
EO_XML

while( 1 ) {
    my $p = XML::DOM::Parser->new;
    my $doc = $p->parse($xml);
    $doc->dispose;
}
__END__


-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: Tue, 06 Dec 2005 01:01:13 GMT
From: "Fred Toewe" <ftoewe@austin.rr.com>
Subject: Win32::OLE::GetObj question
Message-Id: <tp5lf.31503$%i.27544@tornado.texas.rr.com>

Dear List,

Please excuse if this is a well known fact, but I need help.  If it is,
please just give me a pointer to the location of the answer.

I need to scrape data from an Excel file (that belongs to another group and
therefore can probably not be altered) and the darn thing is setup to
politely encourage 'ReadOnly access'.  This causes a dialog box to open
asking whether to open as ReadOnly or not.

My problem is this dialog box - it seems to have to be answered manually
rather than programmatically.  Is there a way around this?

I have tried setting ReadOnly = 1 in the argument list, but not succeeded,
so far.  Perhaps I did it wrong.  I'm using Activestate Perl 5.8.7 with
Win32:: OLE.

Thanks for any advice and cheers.
Fred







------------------------------

Date: Tue, 06 Dec 2005 01:51:57 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Win32::OLE::GetObj question
Message-Id: <Xns9723D447CAB0Dasu1cornelledu@127.0.0.1>

"Fred Toewe" <ftoewe@austin.rr.com> wrote in
news:tp5lf.31503$%i.27544@tornado.texas.rr.com: 

> Dear List,
> 
> Please excuse if this is a well known fact, but I need help.  If it
> is, please just give me a pointer to the location of the answer.
> 
> I need to scrape data from an Excel file (that belongs to another
> group and therefore can probably not be altered) and the darn thing is
> setup to politely encourage 'ReadOnly access'.  This causes a dialog
> box to open asking whether to open as ReadOnly or not.
> 
> My problem is this dialog box - it seems to have to be answered
> manually rather than programmatically.  Is there a way around this?
> 
> I have tried setting ReadOnly = 1 in the argument list, but not
> succeeded, so far.  Perhaps I did it wrong.  I'm using Activestate
> Perl 5.8.7 with Win32:: OLE.

You can access MS VBA editor from Tools -> Macro. Once in the editor, 
use View -> Object Browser to get information about objects, methods, 
and properties.

Now, you can see:

Function Open(Filename As String, [UpdateLinks], [ReadOnly], [Format], 
[Password], [WriteResPassword], [IgnoreReadOnlyRecommended], [Origin], 
[Delimiter], [Editable], [Notify], [Converter], [AddToMru], [Local], 
[CorruptLoad]) As Workbook
    Member of Excel.Workbooks

So,

$excel->Workbooks->Open('filename', undef, 1);

should work.

If you have problems, please post a short but complete script still 
exhibiting the problem.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8734
***************************************


home help back first fref pref prev next nref lref last post