Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nav script problem......

Status
Not open for further replies.

JimJx

Technical User
Joined
Feb 16, 2001
Messages
202
Location
US
Hi all,

I am trying to write a script that will take the number of pages in a dir and create links on the bottom of the page for navigation, similar to what Tek-Tips has at the bottom of their pages.

I have a small script that I wrote that in my twisted logic, should work.

The ReadFolder sub is one I got from here (sorry but don't recall who posted it, but a big thanks to them :-) ), so I am confident that it is working correctly

Here is the code that I haveso far....

Code:
#!/usr/bin/perl

$page = $input{'page'};
$folder = "../glocart";

&PrintHeader;
&ReadFolder;
&Show;

$I = $FirstPage;

print &quot;<CENTER>\n&quot;;
print &quot;<TABLE WIDTH=90%>\n&quot;;
print &quot;<TR><TD ALIGN=CENTER>\n&quot;;

&WriteLinx;

print &quot;</TD></TR>\n&quot;;
print &quot;</TABLE>\n<CENTER>\n&quot;;

#############################
# Begin Subs
#############################

sub ReadFolder {
opendir (FOLDER, $folder) or die &quot;No path available.&quot;;
@filenames= readdir(FOLDER);
closedir(FOLDER);

foreach my $file (@filenames) {
	if ($file =~ /prints(\d+)_.*/i) 
         {
         # catch the number
         $num = $1;
         # if new num is largest yet, 
         # replace maxNum with current num
         # do this for all files and you will have
         # largest number in the files.
         if ($num > $maxNum) { $maxNum = $num; } 
         } 

}

#------------------------------------------------------
1;
}

sub Show {
if ($maxNum <= 10) {
	$FirstPage = 1;
 	$LastPage = $maxNum;
  return 1;
}

if ($page <=5)  {
	$FirstPage = 1;
 	$LastPage = 10;
  return 1;
}

if (($page + 5) < ($maxNum + 1))  {
	$FirstPage = $page - 5;
 	$LastPage = $page + 5;
  return 1;
}

if (($page + 5) > $maxNum)  {
	$FirstPage = $maxNum - 10;
 	$LastPage = $maxNum;
  return 1;
}

}

sub WriteLinx  {

if ($page > 1)  {
	print &quot;<A HREF'\&quot;prints($page-1).shtml\&quot;>&quot;;
 	print &quot;Prev Page  &quot;;
  	print &quot;</A>\n&quot;;
   }

for ($I; $I < $LastPage; $I++)  {
	if ($I eq $page)  {
	print &quot; $I \n&quot;;
 	next;
 	}
  print &quot;<A HREF=\&quot;prints$I.shtml\&quot;>&quot;;
  print &quot; $I &quot;;
  print &quot;</A>\n&quot;;
}

if ($page < $maxNum)  {
	print &quot;<A HREF=\&quot;prints($page + 1).shtml\&quot;>&quot;;
 	print &quot;  Next Page&quot;;
  	print &quot;</A>\n&quot;;
   }
}

sub PrintHeader {
  return &quot;Content-type: text/html\n\n&quot;;
}

And the error messages that I am getting from the server.....

<PRE>
malformed header from script. Bad header=
:
/cgi-bin/navlinks.cgi

unable to include &quot;../cgi-bin/navlinks.cgi&quot; in parsed fileprints1.shtml
</PRE>

So, am I completely off base here?

Any suggestions are greatly appreciated....
Jim
 
The problem is that your PrintHeader subroutine only RETURNS the content-type header, it doesn't actually PRINT it. You either need to change the return to a print, or change the code where you call it to &quot;print &PrintHeader;&quot;.
I'd recommend the former.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Hi tsdragon,

Thank you very much for your reply, that did indeed get rid of the error messages. :-)

I seem to have a bad habit of not double-checking the small details that I really need to break.....

Anyway, after getting that cleared up, and searching through here some more, and more tweaking, I got the script working.

Once again, thanks for the help,
Jim
 
Glad I could be of help. It frequently the little problems that will get you, because you don't think to check for them. That's why it's always good to have someone look at the code who doesn't take anything about it for granted. And that's frequently why you can look at a piece of code for hours and not see the problem, but someone else can walk up and spot it in a heartbeat. And haven't we all had that annoying little occurrence happen?
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top