wiz has asked for the wisdom of the Perl Monks concerning the following question:
After about a 10 month hiatus without using perl, I've come back to try and build a new script. This script is basically a blog script which reads from a file, and draws the info out onto the page. I'm new at using subs in this way, and after using c++ and java (yes, blastphamous, but it was for a course) i would like to learn more about OOP with perl. So this array returning script is my first try.
#!/usr/bin/perl -w use strict; use CGI qw/:standard/; my $number_to_display = 1; my $start = 1; my $blogs; getblogs($start, $number_to_display, @blog); print start_html("SignGuy's Online Journal"); print h1("Congradulations!"); print p($blog[0]), br(); print end_html(); sub getblogs($start, $number_to_display, \@blogs) { open (BLOG, '<blog.db') || die "This script can't open the blog da +tabase $!"; #opening the blog #making the array to hold the info for #the numbered blogs my $x = $start, $y = $number_to_display; #x is the number i'm going to test to see #if it's the number i'm supposed to start on #y is the number i'm going to test to see #if i've displayed all my results or not while (<BLOG>) { if ($_ =~ /$x/) { $blogs[$number_to_display - +$y] = <BLOG>; $x--; $y--; if (!$x || !$y) {last;} } } } _DATA_ 3 This is a test blog. 2 Perl is my god! 1 Dan Simmons is a good author
All the actual code stuff that does not revolve around the array or the sub works. My question today is to see if anyone can augment my stupidity, by telling me the problems with this script. It is far from finished, but i hope this will get me on my way.
The point of the $x and $y variables is that it will show all the records that i tell it to show, and if the list runs out, it just cancels. The data is to be shown in reverse order, from the most current to the oldest (hence the 3 being first. that would be the latest entry). Thank you in advance for all your help!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Subs and Arrays - A blog script problem
by chromatic (Archbishop) on Jul 11, 2002 at 00:05 UTC | |
|
Re: Subs and Arrays - A blog script problem
by Aristotle (Chancellor) on Jul 11, 2002 at 03:12 UTC |