I am in my learning stages of perl and I am creating a website that implements my progress. This is a script that obviously prints my quote of the day. My question is really a request for comments on my approach. Am I doing anything extra that could be left out? What can I do to improve this? I played around with rand() a bunch of ways until I found out I could use rand the way I did. I know this is a simple script, but I think starting out small is good so I can move what I learn to the bigger scripts :)
Methods I used prior to final choice:
srand;
$index = rand(0..10);
print "$quotes[$index]";
----------
srand;
@rquotes = rand(@quotes);
print "$rquotes[3]";
.... and some others you can see I went through some testing and retesting of ideas until I got one that worked, so I just want to know if my methods are good for learning perl better. Basically I would just like any comments, tips, or criticisms from all. :)
#!/usr/bin/perl -w
use strict;
srand;
my $quotes_file = '../quotes/quotes.txt';
open (QFILE, "<$quotes_file")
|| die "Error: could not open $quotes_file:$!\n";
my @quotes = <QFILE>;
my $quote = $quotes[rand(@quotes)];
print "Content-Type: text/html\n\n";
print "$quote";
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.