O
ofer
Hi, I got a file with many quotations by Larry Wall.
The file uses the fortune cookie format:
All language designers are arrogant. Goes with the territory...
-- Larry Wall in <[email protected]
%
Although the Perl Slogan is There's More Than One Way to Do It, I
hesitate
to make 10 ways to do something.
-- Larry Wall in <[email protected]>
%
And don't tell me there isn't one bit of difference between null and
space,
because that's exactly how much difference there is.
-- Larry Wall in <[email protected]>
%
"And I don't like doing silly things (except on purpose)."
-- Larry Wall in <[email protected]>
%
Each time when a visitor comes visit me in my website, I want him to
view a quotation by Larry Wall, and I want it to be a random one.
I have an idea about how to do it, but I think it sucks:
1. Get this file to memory using slurp ( the file is 60kb )
2. count how many times we have "\n%\n" in the file
3. generate a random number that will fit the results from ( 2 )
4. count "\n%\n" until we get to the random number
5. take the quote from there
It looks pretty bad, I know.
Got any other idea for me how to do it?
The file uses the fortune cookie format:
All language designers are arrogant. Goes with the territory...
-- Larry Wall in <[email protected]
%
Although the Perl Slogan is There's More Than One Way to Do It, I
hesitate
to make 10 ways to do something.
-- Larry Wall in <[email protected]>
%
And don't tell me there isn't one bit of difference between null and
space,
because that's exactly how much difference there is.
-- Larry Wall in <[email protected]>
%
"And I don't like doing silly things (except on purpose)."
-- Larry Wall in <[email protected]>
%
Each time when a visitor comes visit me in my website, I want him to
view a quotation by Larry Wall, and I want it to be a random one.
I have an idea about how to do it, but I think it sucks:
1. Get this file to memory using slurp ( the file is 60kb )
2. count how many times we have "\n%\n" in the file
3. generate a random number that will fit the results from ( 2 )
4. count "\n%\n" until we get to the random number
5. take the quote from there
It looks pretty bad, I know.
Got any other idea for me how to do it?