cybär has asked for the wisdom of the Perl Monks concerning the following question:

I have a problem: this part of code counts the documents in the notes database. After that he should print the subject text from each document, but it doesn't work. why? Please help !
# öffnet Notes und zählt die Dokumente in der Inbox 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"; $Database = $Notes->GetDatabase('', 'help4.nsf'); $Database -> OpenMail; $Inbox_view = $Database -> GetView('($Inbox)'); $inbox_documents = $Inbox_view -> AllEntries; $Count = $inbox_documents -> {Count}; print "There are $Count documents in the database.\n"; for (my $Index = 1 ; $Index <= $Count ; ++$Index) { my $Document = $inbox_documents->GetNthDocument($Index); print $Document->{Subject}->{Text},"\n"; my @Values = $Document->{Index_Entries}; foreach my $Value (@Values) { print " Index: $Value\n"; } last unless $Index < 10; }

20050422 Cleaned up by Corion: Changed <br> tags to newlines

Replies are listed 'Best First'.
Re: notes perl problem
by cog (Parson) on Apr 22, 2005 at 09:32 UTC
    but it doesn't work. why?

    Precisely my question. Why, cybär? :-)

    Have a look at Dru's homenode, to his section "Tips on posting"

    Read point number 4:

    4. Explain what the problem is and include any error messages.

    Saying "it doesn't work" won't get you anywhere, because we don't have any clue as to what is wrong with it, but, if OTOH, you explain what it is doing wrongly, for instance, and perhaps include any error messages that might being generated, we will probably be able to help :-)

    Don't take this the wrong way; you're new to the monastery and you obviously don't know how it works. Follow my tip ;-) Tell us how and why it doesn't work. Then we'll try to help you with the code.

    Ohm and speaking of code: always use strict; and use warnings;, and indentation is also helpful.

Re: notes perl problem
by starbolin (Hermit) on Apr 22, 2005 at 14:59 UTC

    Welcome to Perl Monks cybär,

    Having said that I hope you brought a thick skin because I have to chastize you. The code you posted is not your own. This document is from Here If you can't bother to write it yourself and understand it then how can you expect us to put the effort in to debug it??

    Sorry to rant on you but it takes time to look this stuff up and cross check what I post. Then half way through I find that the poster didn't write the code. Oh, well. Since I already did the work and you've been suitably chastized. Here are a few of the errors.

    This line does not do what you think:

    my ($Version) = ($Notes->{NotesVersion} =~ /\s*(.*\S)\s*$/); ###()=>$Version now contains the number of matches. Probably one.

    I can't be sure about this line as I don't have the documents

     $Inbox_view = $Database -> GetView('($Inbox)');

    It's passing a string not a reference to an array. I bet the poster doesn't have the documentation either.

    I would take this line out altogether:

     last unless $Index < 10;

    Do yourself a favor cybär and read the documentation for what you are trying to do, write some code, then post it here for comment. You'll find us, if not nice then, at least, helpfull if you do this.

    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}
      I agree with you 97%. Here's where I don't agree:
      This line does not do what you think:
      my ($Version) = ($Notes->{NotesVersion} =~ /\s*(.*\S)\s*$/); ###()=>$Version now contains the number of matches. Probably one.
      The evaluation is in list context($Version is inside round parens), so a list of group matches is returned - as an example:
      #!/usr/bin/perl use strict; use warnings; my $teststr = "ciao a tutti"; my ($sep) = ($teststr =~ /\w+ (\w+) \w+/); print "result: [$sep]\n"; __END__ result: [a]

      Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

      Don't fool yourself.
Re: notes perl problem
by tcf03 (Deacon) on Apr 22, 2005 at 09:29 UTC
    I came across this getnotes.pl when researching a similar problem for a friend. Thought it might help

    Ted