Hello. For my website, I have a section where I offer quotes. To make it easier to update and expand, I am changing it from HTML to perl. I have the quotes in several files, and they all follow the same format. My problem, however, is extracting the information I need and storing it properly. First, I'll show a brief snippet of the format.
/-aAesop
/-sTyranny
/-qAny excuse will serve a tyrant.
/-sWise Sayings
/-qIt is easy to be brave from a safe distance.
/-sWise Sayings
/-qIt is not only fine feathers that make fine birds.
/-sWise Sayings
/-qWe often despise what is most useful to us.
/-sWise Sayings
/-qNever soar aloft on an enemy's pinions.
/-sWise Sayings
/-qExample is the best precept.
/-sWise Sayings
/-qThinking to get at once all the gold the Goose could give, he kille
+d it and opened it only to find,--nothing.
/-aDante Alighieri
/-sLiberty,Freedom
/-qMankind is at its best when it is most free. This will be clear if
+we grasp the principle of liberty. We must recall that the basic prin
+ciple of liberty is freedom of choice, which saying many have on thei
+r lips but few in their minds.
/-a represents the author.
/-s represents the subject.
/-q represents the quote.
I have some code to cycle through the files, get each chunk of the current file, then to retrieve the author. However my trouble is with getting the subject and quotes, and then in storing it.
I wish to store the file in a way where I can retrieve the quotes with ease. For example, if someone wishes to look up all the quotes with the category "x", then something like the look-up call $subject{x} should contain data of all quotes of such a subject. What I have is below, all else I am troubled with:
my @files = qw(quotePAGE1 quotePAGE2);
for @files {
open IN, $_ or die "failed opening file $_, at";
$\ = "\n\n";
my $num = 0;
my $chunk;
while($chunk = <IN>) {
++$num;
$chunk =~ s|^/-a(\S+)[^/n]*\n|| or
die "no author? file $_, chunk $num; at";
while($chunk =~ s|/-s(\S+)[^\n]*\n/-q [end of code]
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.