If you're new to Programming, then you have a little longer journey .. but if I were going to distill Programming into a little recipe, it would be something like this:
- Figure out what you're trying to do. When in doubt, leave some stuff out .. you can add it in later.
- Make a list of the various steps you're going to need to do. Just write it out on a piece of paper. Review that. Think about it. Drink a cup of coffee. Review it again.
- Get the framework going .. which means, translate some of your 'list' into code, and get something really simple running.
- Gradually add the elements on your list, testing as you go.
- Resist the temptation to throw something together that 'mostly' works. Test as rigourously as possible.
- Once you have a version that works, save it somewhere. I like to use rcs because it's dead simple .. but you can just copy your source code file to a file with the name 'foo.1' or 'foo.2005-04-18'. Once you've done that, you have the freedom to get hacking again, without any worry that you'll 'improve' the original and break it in some mysterious way .. without any way to go back to the version that worked.
The three features you've listed are
- Put heading elements like '3 -- Skippy has a Picnic' in 'h2' tags;
- Wrap text like _this is italicized_ with italic tags; and
- Wrap big blocks of text in parapgraph tags, making one big HTML page from your input.
Is this right?
I'll check back in a bit.
Alex / talexb / Toronto
"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds
| [reply] [d/l] |
#!/usr/bin/perl
use English;
use diagnostics;
print "html body\n";
while ($line = <>) {
if ($line =~ m/Emma [[:punct:]]/) {
print "h2 $line h2\n";
}
if ($line =~ m/CHAPTER (.*)/) {
print "h2 $line h2\n";
}
if ($line =~ m/Jane Austen/) {
print "h2 $line h2\n";
}
if ($line =~ m/VOLUME (.*)/) {
print "h2 $line h2\n";
}
if ( not ( $line =~ m/Jane Austen/) ) {
if ( not ( $line =~ m/Emma [[:punct:]]/)) {
if ( not ( $line =~ m/CHAPTER (.*)/)) {
if ( not ( $line =~ m/VOLUME (.*)/)) {
$line =~ s|\b_|<i>|g;
$line =~ s|_\b|</i>|g;
print $line;
}
}
}
}
}
print "body html\n";
This should do everything but not the paragraph elements!
Any guidance would be great!
I have left out the "<" brackets so that it will display properly
Edit by tye: Add CODE tags
| [reply] [d/l] |