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!


----------------------------
Wiz, The VooDoo Doll
Head Master of 12:30 Productions
My site in progress
----------------------------

In reply to Subs and Arrays - A blog script problem by wiz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.