if ($FORM{'type'} eq "db") { my %UDIoutput = (); my $count = 0; for my $line (@DATABASE) { $count++; my ($type,$datestamp,$file,$title) = split(/\e/, $line); $file =~ s/\//,/g; my $PIDurl = $HOSTurl."?PID=".$file; my $JSONurl = $HOSTurl."?PID=".$file."&udi=json&type=pid"; my %entry = ( 'datestamp' => $datestamp, 'pid' => $PIDurl, 'json' => $JSONurl); %UDIoutput = ( $count => \%entry ); } # create and sort the JSON ouput use JSON::PP; my $json_text = JSON::PP->new()->sort_by(sub { $JSON::PP::a cmp $JSON::PP::b })->pretty(1)->encode(\%UDIoutput); print "Content-type: text/html\n\n"; print $json_text; }