G
Grady Weyenberg
Hi,
I have @list=($obj_1,$obj_2,...) where each $obj, although of different
classes, have a common inherited method, $obj->name.
I am trying to sort @list alphabetically using the value of $obj->name.
I have tried
@list = sort {$a->name cmp $b->name} @list;
but this fails with:
'Can't call method "name" without a package or object reference.'
and I'm not sure how to pass a reference in this context.
Will this be possible using Perl's sort directly on the object list, or
will I need to write my own sorting function?
Thanks,
Grady
I have @list=($obj_1,$obj_2,...) where each $obj, although of different
classes, have a common inherited method, $obj->name.
I am trying to sort @list alphabetically using the value of $obj->name.
I have tried
@list = sort {$a->name cmp $b->name} @list;
but this fails with:
'Can't call method "name" without a package or object reference.'
and I'm not sure how to pass a reference in this context.
Will this be possible using Perl's sort directly on the object list, or
will I need to write my own sorting function?
Thanks,
Grady