Hello List,

I have a sort() issue that is a bit odd and any input wouls be most appreciated :)

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()

$a/$b->part('Name') returns an object that also has a method called value() or undefined if there is no "Name" part

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."

So how can I keep my sort() but avoid/work with the "can't call method on undefined value" error when $a/$b->part('Name') returns undef instead of an object?

I've put them in valriables depending on defined()ness and done

 $name_a cmp $name_b

Which is error free but also doesn't appear to sort it properly :(

TIA!

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to