in reply to Variable will not stay shared in subroutine
Here is a quick rewrite:
Note that the use of an anonymous function means that the function is lexically named, and is always bound to the lexical variable in its name space. The previous naming issue is now just gone.sub sort_results { #======================================== # Sort results in descending order # by date and ascending by document name # within a date. #======================================== my $self = shift; my $database = $self->{_database}; my $sort_sub = sub { $database->[$b]->{numeric_date} <=> $database->[$a]->{numeric_date +} or $database->[$a]->{document_name} cmp $database->[$b]->{document_na +me} or $a <=> $b; }; @{$self->{_search_hits}} = sort $sort_sub @{$self->{_search_hits}}; + }
|
|---|