Re: $head->get issues possibly.
Mark Overmeer <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.mail-box |
|---|---|
| Organization | MARKOV Solutions |
| Message-ID | <[email protected]> |
* Roderick A. Anderson ([email protected]) [040405 19:01]: > The problems is the get method on some messages is returning null > values and this causes other code later in the scripts to fail. The short > questions is there a way to have the get methods to return at least an > empty string? When programming in undetermined environments you have to be constantly aware that things may not be what you expect. In this case: messages may not be in a correct format. As others already stated, undef is a useful return. I have the choice of, either write my $from = $head->get('From') or return; # or exit, or next my $from = $head->get('From') || ''; # set default Best would be my $from = $head->get('From') // ''; But that requires perl 5.9 or Merijn's 'err' patch. > Currently I'm doing the > $from .= ''; $from ||= ''; # is much better In this specific case, you could also do: my @from = $msg->from; This is all common Perl (you will have these options/problems in all Perl programs) and is therefore not included in the MailBox documentation. Although... I could include some examples with these trics anyway... -- MarkOv ------------------------------------------------------------------------ drs Mark A.C.J. Overmeer MARKOV Solutions [email protected] [email protected] http://Mark.Overmeer.net http://solutions.overmeer.net