That's swell. So you fixed your problem on your own, and:
- You never told us what the real problem was -- you didn't clarify what you meant by "doesn't work at all", except to show the generic failure message that appears whenever a cgi script dies before it finishes sending output to the http client.
- You never gave any hint whether you knew enough to check the http server's error log, to see what sort of failure message your initial script was generating, let alone tell us what was in that failure message.
- You posted a repaired version of the code (I guessing this succeeds in a complete HTML stream for the client?), and you tell us there are subtle differences relative to the OP... Since you don't comment the changes, I guess I'll just take your word for it, because trying to diff the two versions myself is more work than I want to do.
- You say there is more work to do -- something about displaying files as URLs -- but... well, you're printing the hash keys returned from your search as href's... Those aren't the "files"? They are the files, but the hrefs aren't working? I don't know what you mean.
Anyway, good luck with that. If you want us to help, try to help us understand a little better.