See the FAQ
How do I select a random line from a file?.
That algorithm is far more memory efficient then what you have.
That said, usually the advice given is to use the
CGI
module. For a script this simple it probably
isn't necessary, but it's a very good idea when you start
wanting to parse parameters to your script.
Also, when you start doing real
CGI programming, you should use the
-T
flag.
I wonder if you
really want
text/plain for your content type,
and not
text/html.
That said, when you had trouble with rand, what I think
you should have done, is check out the documentation.
There is plenty of documentation on this site,
as well as elsewhere.
Additionally, documentation comes with perl, in the
form of the perldoc command, or HTML files
with the (windows) ActiveState version.
From the documentation it is fairly easy to rule out
the methods you tried that failed. Don't guess on how
something works; you can look it up.
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.