CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Navigation inside perl scripts.

 



patk
Deleted

Jan 14, 2000, 9:48 PM

Post #1 of 2 (2240 views)
Navigation inside perl scripts. Can't Post

I am attempting to begin
hosting-cgi. I have
no problems so far,
I have 5 programs up.
My problem, however, is
navigation. Right now I just
have a table with links to all
the programs. But when I add to
or delete to the navigation
I have to update like 35
some files. Any suggestions on how I can
fix this to only have to update one file?
Please remember this is inside the CGI scripts so I can not use SSI, and I need to be able to pass information through
IE <a href="user.cgi?usrname=$usrname>LINK</a>


Jasmine
Administrator

Jan 15, 2000, 1:06 PM

Post #2 of 2 (2240 views)
Re: Navigation inside perl scripts. [In reply to] Can't Post

Probably the easiest way to do this is to create a library that contains your links, then to require the library in each program.

Putting it in its own library file (within a subroutine is a good idea), requiring the library, and invoking the subroutine after $usrname has been defined should do the trick.

Example:

code for links.pl

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


######################
# links.pl
#
# Contains the links for navigation
# between programs to maintaining
# username.


#####################
# SUB NAVIGATION
#
# Usage: $whatever = navigation($username)
#
# Description: This subroutine will take
# the username that's passed to it and
# return the list of links with the username
# incorporated into the links.

sub navigation {

my $user = shift;

my $links = qq~
<a href="program1.cgi?usrname=$user>Program 1</a><BR>

<a href="program2.cgi?usrname=$user>Program 2</a><BR>

<a href="program3.cgi?usrname=$user>Program 3</a><BR>

~;
return $links;
}

1;
</pre><HR></BLOCKQUOTE>

Then, in each of your programs that will require the links, put:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


require "links.pl";

$username = $FORM{'usrname'};
#or however you get this info

my $navlinks = navigation($usrname);

print qq~ <TABLE><TR><TD>
$navlinks
</TD></TR></TABLE>~;
</pre><HR></BLOCKQUOTE>

Hope this helps.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives