budoka has asked for the wisdom of the Perl Monks concerning the following question:

Dear fellow Senior monks, The last few nights were dark for this junior monk.. I have been trying to get some information from an Lotus notes database. For clarity I start off with the source
use strict; use warnings; use Win32::OLE; use Data::Dumper::Simple; my $Notes = Win32::OLE->new('Notes.NotesSession') or die "Cannot start Lotus Notes Session object.\n"; my $db = $Notes->GetDatabase("server", "c_dir/theDBase.nsf") or die "Could not open database.\n"; my ($Version) = ($Notes->{NotesVersion} =~ /\s*(.*\S)\s*$/); # print "The current user is $Notes->{UserName}.\n"; print "Running Notes \"$Version\" on \"$Notes->{Platform}\".\n\n\n"; my $Count = $db->AllDocuments->Count; print "\nConnected to ", $db->{Title}, " on ", $db->{Server}; print "\nThere are $Count documents in the database.\n"; foreach my $Index (1 .. $Count) { my $doc = $db->AllDocuments->GetNthDocument($Index); my $abst = $doc->GetFirstItem('Abstract'); if ($abst) { print Dumper($abst); print "abstract from index $Index : $abst\n" } }
Now , the blessings from the source... The output I get is :
There are 49443 documents in the database. $abst = bless( {}, 'Win32::OLE' ); abstract from index 8 : Win32::OLE=HASH(0x1a8fe44) $abst = bless( {}, 'Win32::OLE' ); abstract from index 31 : Win32::OLE=HASH(0x1a4b57c) $abst = bless( {}, 'Win32::OLE' ); abstract from index 34 : Win32::OLE=HASH(0x1a4b5dc) Terminating on signal SIGINT(2)
The properties of the field/value I am trying to list :
Field Name: Abstract Data Type: Text Data Length: 39 bytes Seq Num: 1 Dup Item ID: 0 Field Flags: SUMMARY "Incompliancy generated"
I am totally lost, I tried almost everything I can Imagine, if I'm not mistaken the hash is a reference to an object.. Dear senior monks, are you able to shed enlightment to this junior monk ? Thank you in advance, Greetings lost fellow monk.

Replies are listed 'Best First'.
Re: Lotus notes, the blessings but not the insight
by Corion (Patriarch) on Aug 12, 2009 at 09:02 UTC

    Back in the day, I wrote Extract Lotus Notes Mail to HTML. I believe you need to actually access properties of your $abst objects instead of trying to use Data::Dumper on them, as these objects are Windows OLE objects and nothing that Perl could see immediately.

    Also note diotalevi's comments on how my code should have been written instead, so you get better performance.

      Thank you for your comment Corion. I tried to take the recommendations into account and ended took two approaches: #1 - using GetItemValue
      use strict; use warnings; use Win32::OLE; use Data::Dumper::Simple; my $Notes = Win32::OLE->new('Notes.NotesSession') or die "Cannot start Lotus Notes Session object.\n"; my $db = $Notes->GetDatabase("server", "c_dir/theDBase.nsf") or die "Could not open database.\n"; my ($Version) = ($Notes->{NotesVersion} =~ /\s*(.*\S)\s*$/); # print "The current user is $Notes->{UserName}.\n"; print "Running Notes \"$Version\" on \"$Notes->{Platform}\".\n\n\n"; my $Count = $db->AllDocuments->Count; print "\nConnected to ", $db->{Title}, " on ", $db->{Server}; print "\nThere are $Count documents in the database.\n"; my $AllDocuments = $db->AllDocuments; my $doc = $AllDocuments->GetFirstDocument; while ( $doc ) { my $NextDoc = $AllDocuments->GetNextDocument($doc); my $abst = $doc->GetItemValue("Abstract"); if ($abst) { warn Dumper($abst); print "abstract = $abst\n"; } $doc = $NextDoc; }
      This yields the following results :
      There are 49765 documents in the database. abstract = ARRAY(0x1a8fd4c) $abst = [ '' ]; abstract = ARRAY(0x1a4b4bc) $abst = [ '' ]; abstract = ARRAY(0x1a8fe4c) $abst = [ '' ]; abstract = ARRAY(0x1a8fddc) $abst = [ '' ]; abstract = ARRAY(0x1a4b45c) $abst = [ '' ]; abstract = ARRAY(0x1a8fe0c) $abst = [ '' ];
      #2 - using GetFirstItem
      my $AllDocuments = $db->AllDocuments; my $doc = $AllDocuments->GetFirstDocument; while ( $doc ) { my $NextDoc = $AllDocuments->GetNextDocument($doc); my $abst = $doc->GetFirstItem("Abstract"); if ($abst) { warn Dumper($abst); print "abstract = $abst\n"; } $doc = $NextDoc; } }
      Which yields the following results :
      There are 49771 documents in the database. $abst = bless( {}, 'Win32::OLE' ); abstract = Win32::OLE=HASH(0x1a4b53c) $abst = bless( {}, 'Win32::OLE' ); abstract = Win32::OLE=HASH(0x1a4b4cc) $abst = bless( {}, 'Win32::OLE' ); abstract = Win32::OLE=HASH(0x1a4b4ec)
      I am close, which Senior monk can give me the final push ?! I cleaned up the thread, for readability's sake. thank you bart,Corion so far for the assistance.
    A reply falls below the community's threshold of quality. You may see it by logging in.