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!

Subroutine's title.... 1

Status
Not open for further replies.

perlone

Programmer
Joined
May 20, 2001
Messages
438
Location
US
Hi,

I'm working on a script called explore.cgi and it uses lots of subroutine urls like explore.cgi?$email&$pass&mode=10. When the user click on a url "Church", it will go to explore.cgi?mode=10. Here's my half code:

if ($query =~m/10/) {
&town("Church Main Page");

exit(0);
}

sub town {
my ($message) = @_;
my ($title) = @_;

print <<EOF;

<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html; charset=iso-8859-1&quot;>
<title>$title</title>
</head>
<p>$message</p>

#HTML CODES
EOF
}

But when I run the url explore.cgi?mode=10, it will displays &quot;Church Main Page&quot; but the title is the same. Meaning perl's thinks ($title) = @_ is same as ($message) = @_; and it displays the message instead of the title. How do I display title for each one?
 
The problem is the way you are passing and assigning subroutine parameters. The only parameter you are passing to the town subroutine is &quot;Church Main Page&quot;. Inside the town subroutine you are assign the entire parameter LIST to two scalar variables $message and $title. The way you are doing it in two separate statements means that each of them will get the FIRST value in the parameter list (in this case &quot;Church Main Page&quot;. That's why they are coming out the same. If you want the town subroutine to take TWO parameters, you need to combine the first two lines like this:
Code:
my ($message, $title) = @_;
This will assign the first value in the subroutine parameter list (@_) to $message and the second value in the list to $title.

Then you need to change the place where you CALL the town subroutine to pass it TWO parameters, the message first, and then the title, for example:
Code:
&town(&quot;this is the message&quot;, &quot;this is the title&quot;);
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
My pleasure!
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.

Similar threads

Part and Inventory Search

Sponsor

Back
Top