That all depends on what is acceptable I guess. If you want to avoid a lot of IO being done by your script, you could always redirect the browser to the chosen random file. See the method
redirect in
CGI.pm. That will, of course, change your url to this new place, and of course these files must be available via the web browser.
If you want to mask the url, there are still ways to do this. Produce a one-frame frameset that links the chosen page in, for instance.
I really should look this up instead of just tossing it out, but I think it might be possible to stat the directory that these files are in and see if it has changed - in effect, see if any files has been added/deleted. This would allow you to cache your list of index files until further notice. Depending on your setup however, this may or may not be a possible/effective way - meaning, where do you store this list?
If you really want to read the directory and then push the contents to the browser, then I don't see what improvements might be done at all... then again, I'm no optimizing expert I guess. :) Maybe someone will tell us if glob or readdir is the faster/more effective though.
You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.