As far as the original error goes ("Can't use an undefined value as a HASH reference at line 49"), it looks like your problem is this:

$FullName = $Document->GetFirstItem('FullName')->{Text};

The call to $Document->GetFirstItem() must be returning an undefined value. Why it is doing that is for you to figure out...

Aside from that, I've just got a few general comments. Give the code below, which is a modified copy of what you originally had:

use strict; use Win32::OLE; use Data::Dumper; ### Skipped everything that worked... my ($FullName, $Extension); my $Notes = Win32::OLE->new('Notes.NotesSession)' or die "Can't start Notes session: $!"; ### (1) ### my $Database = $Notes->GetDatabase('GLOSPK2', 'iddnames.nsf'); my $AllDocuments = $Database->AllDocuments(); ### (2) ### my $Count = $AllDocuments->Count; ### (3) ### print "There are $DocCount documents in the database.\n"; ### (4) ### for ( my $Index = 1; $Index < $Count; $Index++ ) { # do stuff... }

I had these observations, suggestions, etc. All of them should be taken with a grain of salt, however, given that I've never done any Lotus Notes programming via Perl.

  1. Will GetDatabase() return an error? Why aren't you checking? (I am not familar with the Win32::OLE module myself, so I briefly scanned this, and did notice that there is a Win32::OLE->LastError() function; however, I'm not sure if you can use that. Just an idea...
  2. Why do you need to maintain a separate count? If $AllDocuments is a list, a hash, a list ref, or a hash ref, you can access the count anytime you need it. E.g., the following expression will return a 'count' if it is a hash ref:
    scalar keys %{ $AllDocuments }
  3. Did you mean $Count instead of $DocCount?
  4. The built-in list/hash iteration capabilities of Perl are nice...I would use them. I notice later in your loop you use GetNthDocument. Why not use GetNextDocument if you can't do something like this:

    foreach my $Document ( each %{ $AllDocuments } ) { ... }

    (I cheated and looked at the Notes docs to find that)

Finally, I'd recommend a closer look at your Notes documentation. I found an example in my Notes docs that "shows how you can use a While loop and GetNextDocument to access every document in a view". You may find that example enlightening.

p.s. -- get a PerlMonks account, log in, stick around... you'll like it here. :-)


In reply to Re: Hash problem. by t'mo
in thread Hash problem. 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.