Please have mercy on me,

I humbly submit my plea to those more enlightened who have prevailed over the evils of Lotus Notes.

I'm stuck with a situation where an object returns an array. In perl I receive a reference to an array. When I go through that I get back Win32::OLE=HASH{0xnnn) which I don't know how to handle. I'm trying to do the 'forall' statement in the following notes code:

# Dim rtitem As Variant # Set rtitem = doc.GetFirstItem( "Body" ) # Forall o In rtitem.EmbeddedObjects # If o.Type = EMBED_ATTACHMENT Then # Call o.ExtractFile( "c:\newfiles\" & o.Source ) # Call o.Remove # Call doc.Save( True, True ) # End If # End Forall #End Sub
I think the key is the 'Variant' type but I don't understand what that could be done in PERL.

foreach my $embeddedDoc ( $DocumentBody->{EmbeddedObjects} ) { my $edocType =$embeddedDoc->{Type}; # Above returns a blank if ( $edocType eq 'EMBED_ATTACHMENT' ) { print "Embedded Attachment!\n"; } elseif ( $edocType eq 'RICH_TEXT' ) { print "Some sort of Rich Document\n"; } else { print "Unknown Attachment!\n"; } }
Here's the full text of my code. The program is supposed to loop into a Notes e-mail database and tell me if the documents inside have an attachment and what kind. It's based on the code sample in the ActiveState 5.6 PERL HTML.

use strict; use Win32::OLE; my $Notes = Win32::OLE->new('Notes.NotesSession') or die "Cannot start Lotus Notes Session object.\n"; my ($Version) = ($Notes->{NotesVersion} =~ /\s*(.*\S)\s*$/); print "The current user is $Notes->{UserName}.\n"; print "Running Notes \"$Version\" on \"$Notes->{Platform}\".\n"; #my $Database = $Notes->GetDatabase('', 'help4.nsf'); # muser.nsf -- local mail file my $Database = $Notes->GetDatabase('', 'muser.nsf'); my $AllDocuments = $Database->AllDocuments; my $Count = $AllDocuments->Count; print "There are $Count documents in the database.\n"; for (my $Index = 1 ; $Index <= $Count ; ++$Index) { my $Document = $AllDocuments->GetNthDocument($Index); # Get subget of document printf "$Index. %s\n", $Document->GetFirstItem('Subject')->{Text}; # He called the Text property of Subject, how did he know?-^^^^^^ if ( $Document->HasEmbedded ) { my $DocumentBody = $Document->GetFirstItem('Body'); #my $bodytext = $Document->GetFirstItem('Body')->{Text}; #print $bodytext."\n"; # Works occasionally, but not always foreach my $embeddedDoc ( $DocumentBody->{EmbeddedObjects} ) { # I asked for an array of embedded objects # but what I get back is an array reference my $edocType =$embeddedDoc->{Type}; # This yields nothing if ( $edocType eq 'EMBED_ATTACHMENT' ) { print "Embedded Attachment!\n"; } elseif ( $edocType eq 'RICH_TEXT' ) { print "Some sort of Rich Document\n"; } else { print "Unknown Attachment!\n"; } # I get back Win32::OLE=hash(0xnnnn) #my $embed_type = ${$embeddedDoc}{Type} #print $embed_type."\n" } } # limiter last unless $Index < 100; # Get only 5 entries } # Sample notes code that I'm trying to copy # #Sub Click(Source As Button) # Dim session As New NotesSession # Dim db As NotesDatabase # Dim collection As NotesDocumentCollection # Dim doc As NotesDocument # Set db = session.CurrentDatabase # Set collection = db.AllDocuments # For i = 1 To collection.Count # Set doc = collection.GetNthDocument( i ) # If doc.HasEmbedded Then # Call detachFiles( doc ) # End If # Next #End Sub #Sub detachFiles( doc As NotesDocument ) # Dim rtitem As Variant # Set rtitem = doc.GetFirstItem( "Body" ) # Forall o In rtitem.EmbeddedObjects # If o.Type = EMBED_ATTACHMENT Then # Call o.ExtractFile( "c:\newfiles\" & o.Source ) # Call o.Remove # Call doc.Save( True, True ) # End If # End Forall #End Sub # You can get documentation on Notes objects from # http://www.lotus.com/products/lotusscript.nsf

In reply to PERL, Win32::OLE - Lotus Notes and passing objects by Anonymous Monk

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.