In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Rob Richardson) writes:
>--- Peter Scott <[EMAIL PROTECTED]> wrote:
>> In article <[EMAIL PROTECTED]>,
>>  [EMAIL PROTECTED] (Rob Richardson) writes:
>> >sub GetTrainsByTime
>> >{
>> >    my $self = shift;
>> >    my @result;
>> >    my @temp;
>> >    my $aTrain;
>> >    my $aTrainName;
>> >
>> >    # First we build a temporary array of references to trains
>> >    foreach $aTrainName (keys $self)
>>                                   ^ % missing
>> >    {
>> >            push @temp, $self{aTrainName};
>>                                   ^ $ missing
>> 
>> >    }
>> >
>> >    @result = sort {$a->GetCrewCall() cmp $b->GetCrewCall()} @temp;
>> >    return @result;
>> >}
>> 
>> (1) If you wanted to put the keys of a hash into an array, just do it
>> all at once:
>> 
>>      @temp = keys %$self
>
>I am not putting the keys of the hash into the temporary array.  I'm
>putting the values of the hash into the array.

Whoops, okay, then do

        @temp = values %$self

>> (2) If you want to sort the keys of a hash, there's no need to put
>> them into an array.  sort takes a list as input:
>> 
>>      return sort { $a->GetCrewCall cmp $b->GetCrewCall } keys %self
>> 
>
>Since I am not using the keys of the hash, the above line won't work
>for me.

        return sort { $a->GetCrewCall cmp $b->GetCrewCall } values %self

-- 
Peter Scott
http://www.perldebugged.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to