On Tue, Oct 15, 2002 at 10:54:14AM -0400, Chris Benco wrote:
> my $From = $Document->GetFirstItem('From')->{Text} or ();
> 
> This appears to work.  When I run a test the program recovers seemingly
> flawlessly.  My problem is that the script still dies at some point.  When
> I come in the next day it shows a hash reference on an undefined value
> error in line 15. 

Your code still assumes the GetFirstItem() method returns a hash reference. 
It apparently returns undef in some situations.

You must protect against this.  It can be done in various ways; one way is:

    my $first_item = $Document->GetFirstItem('From');
    my $From;
    $From = $$first_item{Text} if ref($first_item) eq 'HASH';

This will leave $From undef if GetFirstItem() doesn't return a hashref, or
the Text key of the hashref is undef.

I'm not sure why someone gave you the advice of using the "or ()".  That
syntax, combined with the 'my' declaration, will result in some strange
behaviour.  I think somebody either gave you bad advice, made a typo
(perhaps they meant || instead of 'or'), or was attempting to solve a
different problem.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to