I am writing a program for my web site that will read a txt file with info in it and print part of it to the screen(like the first 43 lines) and then have a link to the next 43 lines. But when i read from the txt file and store it in an array it stores blank lines as elements of the array( which I don't want) but when I try to remove them using grep it doesnt shrink the array.
Here is my code:
$article=$formdata{'article'};
$page=$formdata{'page'};
$maxlength=43;
$start=($page-1)*$maxlength;
$finish=$page*$maxlength;
$next=$page+1;
$previous=$page-1;
&main;
sub main{
print "Content-type: text/html\n\n";
$file="$basedir$article\.txt";
open(READ, "$file");
@info=<READ>;
close(READ);
@info=grep(!/^ +$/, @info);
$length=@info;
for($i=$start;$i<$finish;$i++){
print"$info[$i]\n";
}
if (($length>$finish)&&($page>1)){
print"<table border=0><tr><td align=left>  <font color=yellow>
+<-
</font> <a href=\"http://www.mysite.net/cgi-bin/article.cgi?articl
+e=
$article&page=$previous\">Continue to the previous page</a></td><t
+d
width=200></td><td align=right><a href=\"http://www.mysite.net/cgi-
bin/article.cgi?article=$article&page=$next\">Continue to the next
+
page</a> <font color=yellow>--></font>  </td></tr></table>
+\n";
}elsif(($length>$finish)&&($page==1)){
print"<table border=0><tr><td align=right><a href=\"http://www.mysite.
+net/cgi-
bin/article.cgi?article=$article&page=$next\">Continue to the next
+
page</a> <font color=yellow>--></font>  </td></tr></table>
+\n";
}
}
Instead of print our the 43 it prints out a few lines then a whole lot of blank spaces. Can anyone help?
Jemts
"If you're traveling in a time machine, and you're eating corn on the cob, I don't think it's going to affect things one way or the other. But here's the point I'm trying to make: Corn on the cob is good, isn't it."
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.