|
I have very little experience with perl. I have a plx/tmpl page that displays a data table based on a @records array. I am able to sort the array by a subkey.
I want to create links out of the column headers then change the sort order based on what the user clicks (ascending/descending). The links change the 'sort' querystring value. I am able to get the querystring with:
my $sortvar = param('sort');
|
|
I coded the tmpl file to change the link when the user clicks it, that part works fine.
I tried this in my plx page but it does not do anything:
if ($sortvar == '1')
{
my @records = map { $_->[0] }
sort { $b->[1] cmp $a->[1] }
map {(my $date = $_->{COMPDATE}) =~ s/<font color="#FF0000">//;
my ($d,$m,$y) = split(/\s+/,$date);
$d = $d<10 ? "0$d" : $d;
$m = $month{lc substr $m,0,3};
[$_,"$y$m$d"]} @records;
}
elsif ($sortvar == '2')
{
my @records = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map {(my $date = $_->{COMPDATE}) =~ s/<font color="#FF0000">//;
my ($d,$m,$y) = split(/\s+/,$date);
$d = $d<10 ? "0$d" : $d;
$m = $month{lc substr $m,0,3};
[$_,"$y$m$d"]} @records;
}
|
|
Any ideas?
|
|
|
The problem: @records was scoped wrong. It was declared globally way above this code snippet so taking out the 'my' in front fixed the problem. As is, it was local to the if statement.
|
|
|
|
|
|
|
// |