Perl and Word have been playing well together for me for a while now on a W2K/ActiveState 5.8.4 platform. A new wrinkle has come up and I'm trying to verify what is in the Word objects I am creating.

I'd expect to be able to examine those objects with Dumper, but when I do so, I seem to get stuck in a loop and the Windows Task Manager shows the VM Size of my perl.exe pgm getting larger and larger at which point I kill the perl.exe process.

The following sample code extracts the essence of my Dumper test. My question is, "Aren't I able to look at these objects with Dumper?" (The if 0 and if 1 thingies give me easy-to-find debugging hooks to play with.)

(For what it's worth, the original problem I'm investigating is that something new/weird is happening in the Save process. And I don't think I did anything and I'm wondering if something has changed on the OLE side. I can see the Word document being created but when the document is saved to disk, it appears empty. But that's another story....)

use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; use Data::Dumper; # Update: The following line, per advice below, solves my problem: # $Data::Dumper::Maxdepth=2; # check if Word exists my $x = Win32::OLE->GetActiveObject('Word.Application'); die "Word not Installed" if $@; warn "1 OK to here.\n"; # start Word program, die if unable to unless (defined $x) { unless ( $x = Win32::OLE->new('Word.Application', sub { $_[0]->Quit; }) ) { die "Cannot start Word.\n"; } } warn "2 OK to here.\n"; do_dumper( 'wobjX:', $x ) if 1; warn "3 OK to here.\n"; my $template_file = 'e:\\aa\\myfile.dot'; my $d; unless ( $d = $x->Documents->Add( $template_file ) ) { die "Cannot open file '$template_file': $!\n"; } do_dumper( 'wobjD:', $d ) if 0; undef $x; undef $d; warn "4 OK to here.\n"; sub do_dumper { my ( $label, $variable ) = @_; my $msg = Dumper( $variable ); open P2W, ">> p2w_out.txt"; print P2W "$label:\n$msg\n"; #warn "$label:\n$msg\n"; close P2W; }

Update: Made some minor revisions to sample code to fix cosmetic problems with quoting. Thanks for the advice--I'm getting stuff I can read now. :-)


In reply to Win32::OLE Word objects and Dumper by ff

Title:
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, details, 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, summary, 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.