J
Jay Eckles
I'm having some difficulty figuring out why a bit of code isn't
working. I'm hoping you can help.
I have a funciton that retuns an array of objects. I have defined the
class myself (the definition is below, it's quite short). I want to
sort that array, using a subroutine to define how the objects should
be sorted. Here's the line I use to call sort:
@events = sort calendar::timeCompare @events
Where calendar::timeCompare is the subroutine I've defined in a
package I called calendar.
The problem is that in timeCompare, I'm not able to access any of the
members of the objects $a and $b. For example,
package calendar ;
....
sub timeCompare{
print STDERR "a when: $a->{'when'}\n" ;
print STDERR "a summary: $a->{'summary'}\n" ;
....
gives me the following output:
a when:
a summary:
(I know that the object have values for 'when' and 'summary' because I
use the objects, after the sort call, and they have values).
Without access to these members, I can't sort the objects. Is there
any trick to sorting objects as opposed to scalar values?
Thanks for any assistance you can lend.
Jay Eckles
PS - here's the class definition:
###Event class
package Event ;
sub new {
my($class) = shift;
bless {
"date" => undef,
"when" => undef,
"location" => undef,
"summary" => undef,
"details" => undef
}, $class;
}
PPS - this is part of an open source project called CGI Calendar,
http://sourceforge.net/projects/cgicalendar
working. I'm hoping you can help.
I have a funciton that retuns an array of objects. I have defined the
class myself (the definition is below, it's quite short). I want to
sort that array, using a subroutine to define how the objects should
be sorted. Here's the line I use to call sort:
@events = sort calendar::timeCompare @events
Where calendar::timeCompare is the subroutine I've defined in a
package I called calendar.
The problem is that in timeCompare, I'm not able to access any of the
members of the objects $a and $b. For example,
package calendar ;
....
sub timeCompare{
print STDERR "a when: $a->{'when'}\n" ;
print STDERR "a summary: $a->{'summary'}\n" ;
....
gives me the following output:
a when:
a summary:
(I know that the object have values for 'when' and 'summary' because I
use the objects, after the sort call, and they have values).
Without access to these members, I can't sort the objects. Is there
any trick to sorting objects as opposed to scalar values?
Thanks for any assistance you can lend.
Jay Eckles
PS - here's the class definition:
###Event class
package Event ;
sub new {
my($class) = shift;
bless {
"date" => undef,
"when" => undef,
"location" => undef,
"summary" => undef,
"details" => undef
}, $class;
}
PPS - this is part of an open source project called CGI Calendar,
http://sourceforge.net/projects/cgicalendar