Timothy Johnson wrote:
Just a thought, but couldn't you put the logic in your grep statement?
Something like this:
grep {defined($_->value()) or defined($_->part('Name')->value())}
@objects;
The only problem is then that the object woudl be completely skipped.
I need all objects regardless of if their part call returns and object
or undef :(
Perhaps their is a logic I can do something like that, like 2 sort()s or
a map() or ??
Thanks for the input!
-----Original Message-----
From: JupiterHost.Net [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 25, 2006 12:22 PM
To: beginners@perl.org
Subject: sort {} to work with undef values when its expecting an object
<snip>
The code:
use strict;
use warnings;
...
for my $obj(
sort {
$a->value() cmp $b->value()
||
$a->part('Name')->value() cmp $b->part('Name')->value()
}
grep { defined } @objects
) {
...
$a/$b->value() always works since if $a/$b is defined its an object with
a method called value()
<snip>
The sort works perfect for what I need, *except* when
$a/$b->part('Name') does not return an object itself. Then it dies with
"Can't call method value() on undefined value."
<snip>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>